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