CRIS v10: Cleanup of drivers/gpio.c

- Change parameters of gpio_write (const char * buf -> const char __user *buf)
- Don't initialize static variables to zero.
- Remove useless casts from void.
- Change name of interrupt routine (gpio_pa_interrupt -> gpio_interrupt)
- Use kzmalloc instead of allocating memory and zeroing it manually.
- Correct casts for copy_to_user and copy_from_user to (void __user *)
- Make file_operations gpio_fops static.
- Make ioif_watcher static, not used outside this file.

+29 -32
+29 -32
arch/cris/arch-v10/drivers/gpio.c
··· 46 #endif 47 48 static int gpio_ioctl(struct inode *inode, struct file *file, 49 - unsigned int cmd, unsigned long arg); 50 - static ssize_t gpio_write(struct file * file, const char * buf, size_t count, 51 - loff_t *off); 52 static int gpio_open(struct inode *inode, struct file *filp); 53 static int gpio_release(struct inode *inode, struct file *filp); 54 static unsigned int gpio_poll(struct file *filp, struct poll_table_struct *wait); ··· 74 75 /* linked list of alarms to check for */ 76 77 - static struct gpio_private *alarmlist = 0; 78 79 - static int gpio_some_alarms = 0; /* Set if someone uses alarm */ 80 - static unsigned long gpio_pa_irq_enabled_mask = 0; 81 82 static DEFINE_SPINLOCK(gpio_lock); /* Protect directions etc */ 83 ··· 145 static unsigned int gpio_poll(struct file *file, poll_table *wait) 146 { 147 unsigned int mask = 0; 148 - struct gpio_private *priv = (struct gpio_private *)file->private_data; 149 unsigned long data; 150 unsigned long flags; 151 ··· 222 } 223 224 static irqreturn_t 225 - gpio_pa_interrupt(int irq, void *dev_id) 226 { 227 unsigned long tmp; 228 unsigned long flags; ··· 272 gpio_write_bit(priv, data, i); 273 } 274 275 - static ssize_t gpio_write(struct file * file, const char * buf, size_t count, 276 - loff_t *off) 277 { 278 - struct gpio_private *priv = (struct gpio_private *)file->private_data; 279 unsigned long flags; 280 ssize_t retval = count; 281 ··· 318 if (p > GPIO_MINOR_LAST) 319 return -EINVAL; 320 321 - priv = kmalloc(sizeof(struct gpio_private), GFP_KERNEL); 322 323 if (!priv) 324 return -ENOMEM; 325 - 326 - memset(priv, 0, sizeof(*priv)); 327 328 priv->minor = p; 329 ··· 349 priv->data_mask = 0; 350 init_waitqueue_head(&priv->alarm_wq); 351 352 - filp->private_data = (void *)priv; 353 354 /* link it into our alarmlist */ 355 spin_lock_irqsave(&gpio_lock, flags); ··· 370 spin_lock_irqsave(&gpio_lock, flags); 371 372 p = alarmlist; 373 - todel = (struct gpio_private *)filp->private_data; 374 375 /* unlink from alarmlist and free the private structure */ 376 ··· 509 unsigned long val; 510 int ret = 0; 511 512 - struct gpio_private *priv = (struct gpio_private *)file->private_data; 513 if (_IOC_TYPE(cmd) != ETRAXGPIO_IOCTYPE) 514 return -EINVAL; 515 ··· 631 } else if (priv->minor == GPIO_MINOR_G) { 632 val = *R_PORT_G_DATA; 633 } 634 - if (copy_to_user((unsigned long*)arg, &val, sizeof(val))) 635 ret = -EFAULT; 636 break; 637 case IO_READ_OUTBITS: ··· 641 } else if (priv->minor == GPIO_MINOR_G) { 642 val = port_g_data_shadow; 643 } 644 - if (copy_to_user((unsigned long*)arg, &val, sizeof(val))) 645 ret = -EFAULT; 646 break; 647 case IO_SETGET_INPUT: 648 /* bits set in *arg is set to input, 649 * *arg updated with current input pins. 650 */ 651 - if (copy_from_user(&val, (unsigned long*)arg, sizeof(val))) 652 { 653 ret = -EFAULT; 654 break; 655 } 656 val = setget_input(priv, val); 657 - if (copy_to_user((unsigned long*)arg, &val, sizeof(val))) 658 ret = -EFAULT; 659 break; 660 case IO_SETGET_OUTPUT: 661 /* bits set in *arg is set to output, 662 * *arg updated with current output pins. 663 */ 664 - if (copy_from_user(&val, (unsigned long *)arg, sizeof(val))) { 665 ret = -EFAULT; 666 break; 667 } 668 val = setget_output(priv, val); 669 - if (copy_to_user((unsigned long*)arg, &val, sizeof(val))) 670 ret = -EFAULT; 671 break; 672 default: ··· 709 return 0; 710 } 711 712 - const struct file_operations gpio_fops = { 713 .owner = THIS_MODULE, 714 .poll = gpio_poll, 715 .ioctl = gpio_ioctl, ··· 718 .release = gpio_release, 719 }; 720 721 - void ioif_watcher(const unsigned int gpio_in_available, 722 - const unsigned int gpio_out_available, 723 - const unsigned char pa_available, 724 - const unsigned char pb_available) 725 { 726 unsigned long int flags; 727 ··· 768 769 /* main driver initialization routine, called from mem.c */ 770 771 - static __init int 772 - gpio_init(void) 773 { 774 int res; 775 #if defined (CONFIG_ETRAX_CSP0_LEDS) ··· 814 printk(KERN_CRIT "err: timer0 irq for gpio\n"); 815 return res; 816 } 817 - res = request_irq(PA_IRQ_NBR, gpio_pa_interrupt, 818 IRQF_SHARED | IRQF_DISABLED, "gpio PA", gpio_name); 819 if (res) 820 printk(KERN_CRIT "err: PA irq for gpio\n"); ··· 823 } 824 825 /* this makes sure that gpio_init is called during kernel boot */ 826 - 827 module_init(gpio_init);
··· 46 #endif 47 48 static int gpio_ioctl(struct inode *inode, struct file *file, 49 + unsigned int cmd, unsigned long arg); 50 + static ssize_t gpio_write(struct file *file, const char __user *buf, 51 + size_t count, loff_t *off); 52 static int gpio_open(struct inode *inode, struct file *filp); 53 static int gpio_release(struct inode *inode, struct file *filp); 54 static unsigned int gpio_poll(struct file *filp, struct poll_table_struct *wait); ··· 74 75 /* linked list of alarms to check for */ 76 77 + static struct gpio_private *alarmlist; 78 79 + static int gpio_some_alarms; /* Set if someone uses alarm */ 80 + static unsigned long gpio_pa_irq_enabled_mask; 81 82 static DEFINE_SPINLOCK(gpio_lock); /* Protect directions etc */ 83 ··· 145 static unsigned int gpio_poll(struct file *file, poll_table *wait) 146 { 147 unsigned int mask = 0; 148 + struct gpio_private *priv = file->private_data; 149 unsigned long data; 150 unsigned long flags; 151 ··· 222 } 223 224 static irqreturn_t 225 + gpio_interrupt(int irq, void *dev_id) 226 { 227 unsigned long tmp; 228 unsigned long flags; ··· 272 gpio_write_bit(priv, data, i); 273 } 274 275 + static ssize_t gpio_write(struct file *file, const char __user *buf, 276 + size_t count, loff_t *off) 277 { 278 + struct gpio_private *priv = file->private_data; 279 unsigned long flags; 280 ssize_t retval = count; 281 ··· 318 if (p > GPIO_MINOR_LAST) 319 return -EINVAL; 320 321 + priv = kzalloc(sizeof(struct gpio_private), GFP_KERNEL); 322 323 if (!priv) 324 return -ENOMEM; 325 326 priv->minor = p; 327 ··· 351 priv->data_mask = 0; 352 init_waitqueue_head(&priv->alarm_wq); 353 354 + filp->private_data = priv; 355 356 /* link it into our alarmlist */ 357 spin_lock_irqsave(&gpio_lock, flags); ··· 372 spin_lock_irqsave(&gpio_lock, flags); 373 374 p = alarmlist; 375 + todel = filp->private_data; 376 377 /* unlink from alarmlist and free the private structure */ 378 ··· 511 unsigned long val; 512 int ret = 0; 513 514 + struct gpio_private *priv = file->private_data; 515 if (_IOC_TYPE(cmd) != ETRAXGPIO_IOCTYPE) 516 return -EINVAL; 517 ··· 633 } else if (priv->minor == GPIO_MINOR_G) { 634 val = *R_PORT_G_DATA; 635 } 636 + if (copy_to_user((void __user *)arg, &val, sizeof(val))) 637 ret = -EFAULT; 638 break; 639 case IO_READ_OUTBITS: ··· 643 } else if (priv->minor == GPIO_MINOR_G) { 644 val = port_g_data_shadow; 645 } 646 + if (copy_to_user((void __user *)arg, &val, sizeof(val))) 647 ret = -EFAULT; 648 break; 649 case IO_SETGET_INPUT: 650 /* bits set in *arg is set to input, 651 * *arg updated with current input pins. 652 */ 653 + if (copy_from_user(&val, (void __user *)arg, sizeof(val))) 654 { 655 ret = -EFAULT; 656 break; 657 } 658 val = setget_input(priv, val); 659 + if (copy_to_user((void __user *)arg, &val, sizeof(val))) 660 ret = -EFAULT; 661 break; 662 case IO_SETGET_OUTPUT: 663 /* bits set in *arg is set to output, 664 * *arg updated with current output pins. 665 */ 666 + if (copy_from_user(&val, (void __user *)arg, sizeof(val))) { 667 ret = -EFAULT; 668 break; 669 } 670 val = setget_output(priv, val); 671 + if (copy_to_user((void __user *)arg, &val, sizeof(val))) 672 ret = -EFAULT; 673 break; 674 default: ··· 711 return 0; 712 } 713 714 + static const struct file_operations gpio_fops = { 715 .owner = THIS_MODULE, 716 .poll = gpio_poll, 717 .ioctl = gpio_ioctl, ··· 720 .release = gpio_release, 721 }; 722 723 + static void ioif_watcher(const unsigned int gpio_in_available, 724 + const unsigned int gpio_out_available, 725 + const unsigned char pa_available, 726 + const unsigned char pb_available) 727 { 728 unsigned long int flags; 729 ··· 770 771 /* main driver initialization routine, called from mem.c */ 772 773 + static int __init gpio_init(void) 774 { 775 int res; 776 #if defined (CONFIG_ETRAX_CSP0_LEDS) ··· 817 printk(KERN_CRIT "err: timer0 irq for gpio\n"); 818 return res; 819 } 820 + res = request_irq(PA_IRQ_NBR, gpio_interrupt, 821 IRQF_SHARED | IRQF_DISABLED, "gpio PA", gpio_name); 822 if (res) 823 printk(KERN_CRIT "err: PA irq for gpio\n"); ··· 826 } 827 828 /* this makes sure that gpio_init is called during kernel boot */ 829 module_init(gpio_init); 830 +