Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad433f23 authored by Jesper Nilsson's avatar Jesper Nilsson
Browse files

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.
parent 5efa1d1c
Loading
Loading
Loading
Loading
+29 −32
Original line number Original line Diff line number Diff line
@@ -47,8 +47,8 @@ static wait_queue_head_t *gpio_wq;


static int gpio_ioctl(struct inode *inode, struct file *file,
static int gpio_ioctl(struct inode *inode, struct file *file,
	unsigned int cmd, unsigned long arg);
	unsigned int cmd, unsigned long arg);
static ssize_t gpio_write(struct file * file, const char * buf, size_t count,
static ssize_t gpio_write(struct file *file, const char __user *buf,
                          loff_t *off);
	size_t count, loff_t *off);
static int gpio_open(struct inode *inode, struct file *filp);
static int gpio_open(struct inode *inode, struct file *filp);
static int gpio_release(struct inode *inode, struct file *filp);
static int gpio_release(struct inode *inode, struct file *filp);
static unsigned int gpio_poll(struct file *filp, struct poll_table_struct *wait);
static unsigned int gpio_poll(struct file *filp, struct poll_table_struct *wait);
@@ -74,10 +74,10 @@ struct gpio_private {


/* linked list of alarms to check for */
/* linked list of alarms to check for */


static struct gpio_private *alarmlist = 0;
static struct gpio_private *alarmlist;


static int gpio_some_alarms = 0; /* Set if someone uses alarm */
static int gpio_some_alarms; /* Set if someone uses alarm */
static unsigned long gpio_pa_irq_enabled_mask = 0;
static unsigned long gpio_pa_irq_enabled_mask;


static DEFINE_SPINLOCK(gpio_lock); /* Protect directions etc */
static DEFINE_SPINLOCK(gpio_lock); /* Protect directions etc */


@@ -145,7 +145,7 @@ static unsigned long dir_g_shadow; /* 1=output */
static unsigned int gpio_poll(struct file *file, poll_table *wait)
static unsigned int gpio_poll(struct file *file, poll_table *wait)
{
{
	unsigned int mask = 0;
	unsigned int mask = 0;
	struct gpio_private *priv = (struct gpio_private *)file->private_data;
	struct gpio_private *priv = file->private_data;
	unsigned long data;
	unsigned long data;
	unsigned long flags;
	unsigned long flags;


@@ -222,7 +222,7 @@ gpio_poll_timer_interrupt(int irq, void *dev_id)
}
}


static irqreturn_t
static irqreturn_t
gpio_pa_interrupt(int irq, void *dev_id)
gpio_interrupt(int irq, void *dev_id)
{
{
	unsigned long tmp;
	unsigned long tmp;
	unsigned long flags;
	unsigned long flags;
@@ -272,10 +272,10 @@ static void gpio_write_byte(struct gpio_private *priv, unsigned char data)
			gpio_write_bit(priv, data, i);
			gpio_write_bit(priv, data, i);
}
}


static ssize_t gpio_write(struct file * file, const char * buf, size_t count,
static ssize_t gpio_write(struct file *file, const char __user *buf,
                          loff_t *off)
	size_t count, loff_t *off)
{
{
	struct gpio_private *priv = (struct gpio_private *)file->private_data;
	struct gpio_private *priv = file->private_data;
	unsigned long flags;
	unsigned long flags;
	ssize_t retval = count;
	ssize_t retval = count;


@@ -318,13 +318,11 @@ gpio_open(struct inode *inode, struct file *filp)
	if (p > GPIO_MINOR_LAST)
	if (p > GPIO_MINOR_LAST)
		return -EINVAL;
		return -EINVAL;


	priv = kmalloc(sizeof(struct gpio_private), GFP_KERNEL);
	priv = kzalloc(sizeof(struct gpio_private), GFP_KERNEL);


	if (!priv)
	if (!priv)
		return -ENOMEM;
		return -ENOMEM;


	memset(priv, 0, sizeof(*priv));

	priv->minor = p;
	priv->minor = p;


	/* initialize the io/alarm struct */
	/* initialize the io/alarm struct */
@@ -351,7 +349,7 @@ gpio_open(struct inode *inode, struct file *filp)
	priv->data_mask = 0;
	priv->data_mask = 0;
	init_waitqueue_head(&priv->alarm_wq);
	init_waitqueue_head(&priv->alarm_wq);


	filp->private_data = (void *)priv;
	filp->private_data = priv;


	/* link it into our alarmlist */
	/* link it into our alarmlist */
	spin_lock_irqsave(&gpio_lock, flags);
	spin_lock_irqsave(&gpio_lock, flags);
@@ -372,7 +370,7 @@ gpio_release(struct inode *inode, struct file *filp)
	spin_lock_irqsave(&gpio_lock, flags);
	spin_lock_irqsave(&gpio_lock, flags);


	p = alarmlist;
	p = alarmlist;
	todel = (struct gpio_private *)filp->private_data;
	todel = filp->private_data;


	/* unlink from alarmlist and free the private structure */
	/* unlink from alarmlist and free the private structure */


@@ -511,7 +509,7 @@ gpio_ioctl(struct inode *inode, struct file *file,
	unsigned long val;
	unsigned long val;
        int ret = 0;
        int ret = 0;


	struct gpio_private *priv = (struct gpio_private *)file->private_data;
	struct gpio_private *priv = file->private_data;
	if (_IOC_TYPE(cmd) != ETRAXGPIO_IOCTYPE)
	if (_IOC_TYPE(cmd) != ETRAXGPIO_IOCTYPE)
		return -EINVAL;
		return -EINVAL;


@@ -633,7 +631,7 @@ gpio_ioctl(struct inode *inode, struct file *file,
		} else if (priv->minor == GPIO_MINOR_G) {
		} else if (priv->minor == GPIO_MINOR_G) {
			val = *R_PORT_G_DATA;
			val = *R_PORT_G_DATA;
		}
		}
		if (copy_to_user((unsigned long*)arg, &val, sizeof(val)))
		if (copy_to_user((void __user *)arg, &val, sizeof(val)))
			ret = -EFAULT;
			ret = -EFAULT;
		break;
		break;
	case IO_READ_OUTBITS:
	case IO_READ_OUTBITS:
@@ -643,32 +641,32 @@ gpio_ioctl(struct inode *inode, struct file *file,
		} else if (priv->minor == GPIO_MINOR_G) {
		} else if (priv->minor == GPIO_MINOR_G) {
			val = port_g_data_shadow;
			val = port_g_data_shadow;
		}
		}
		if (copy_to_user((unsigned long*)arg, &val, sizeof(val)))
		if (copy_to_user((void __user *)arg, &val, sizeof(val)))
			ret = -EFAULT;
			ret = -EFAULT;
		break;
		break;
	case IO_SETGET_INPUT: 
	case IO_SETGET_INPUT: 
		/* bits set in *arg is set to input,
		/* bits set in *arg is set to input,
		 * *arg updated with current input pins.
		 * *arg updated with current input pins.
		 */
		 */
		if (copy_from_user(&val, (unsigned long*)arg, sizeof(val)))
		if (copy_from_user(&val, (void __user *)arg, sizeof(val)))
		{
		{
			ret = -EFAULT;
			ret = -EFAULT;
			break;
			break;
		}
		}
		val = setget_input(priv, val);
		val = setget_input(priv, val);
		if (copy_to_user((unsigned long*)arg, &val, sizeof(val)))
		if (copy_to_user((void __user *)arg, &val, sizeof(val)))
			ret = -EFAULT;
			ret = -EFAULT;
		break;
		break;
	case IO_SETGET_OUTPUT:
	case IO_SETGET_OUTPUT:
		/* bits set in *arg is set to output,
		/* bits set in *arg is set to output,
		 * *arg updated with current output pins.
		 * *arg updated with current output pins.
		 */
		 */
		if (copy_from_user(&val, (unsigned long *)arg, sizeof(val))) {
		if (copy_from_user(&val, (void __user *)arg, sizeof(val))) {
			ret = -EFAULT;
			ret = -EFAULT;
			break;
			break;
		}
		}
		val = setget_output(priv, val);
		val = setget_output(priv, val);
		if (copy_to_user((unsigned long*)arg, &val, sizeof(val)))
		if (copy_to_user((void __user *)arg, &val, sizeof(val)))
			ret = -EFAULT;
			ret = -EFAULT;
		break;
		break;
	default:
	default:
@@ -711,7 +709,7 @@ gpio_leds_ioctl(unsigned int cmd, unsigned long arg)
	return 0;
	return 0;
}
}


const struct file_operations gpio_fops = {
static const struct file_operations gpio_fops = {
	.owner       = THIS_MODULE,
	.owner       = THIS_MODULE,
	.poll        = gpio_poll,
	.poll        = gpio_poll,
	.ioctl       = gpio_ioctl,
	.ioctl       = gpio_ioctl,
@@ -720,7 +718,7 @@ const struct file_operations gpio_fops = {
	.release     = gpio_release,
	.release     = gpio_release,
};
};


void ioif_watcher(const unsigned int gpio_in_available,
static void ioif_watcher(const unsigned int gpio_in_available,
	const unsigned int gpio_out_available,
	const unsigned int gpio_out_available,
	const unsigned char pa_available,
	const unsigned char pa_available,
	const unsigned char pb_available)
	const unsigned char pb_available)
@@ -770,8 +768,7 @@ void ioif_watcher(const unsigned int gpio_in_available,


/* main driver initialization routine, called from mem.c */
/* main driver initialization routine, called from mem.c */


static __init int
static int __init gpio_init(void)
gpio_init(void)
{
{
	int res;
	int res;
#if defined (CONFIG_ETRAX_CSP0_LEDS)
#if defined (CONFIG_ETRAX_CSP0_LEDS)
@@ -817,7 +814,7 @@ gpio_init(void)
		printk(KERN_CRIT "err: timer0 irq for gpio\n");
		printk(KERN_CRIT "err: timer0 irq for gpio\n");
		return res;
		return res;
	}
	}
	res = request_irq(PA_IRQ_NBR, gpio_pa_interrupt,
	res = request_irq(PA_IRQ_NBR, gpio_interrupt,
		IRQF_SHARED | IRQF_DISABLED, "gpio PA", gpio_name);
		IRQF_SHARED | IRQF_DISABLED, "gpio PA", gpio_name);
	if (res)
	if (res)
		printk(KERN_CRIT "err: PA irq for gpio\n");
		printk(KERN_CRIT "err: PA irq for gpio\n");
@@ -826,5 +823,5 @@ gpio_init(void)
}
}


/* this makes sure that gpio_init is called during kernel boot */
/* this makes sure that gpio_init is called during kernel boot */

module_init(gpio_init);
module_init(gpio_init);