Re: [PATCH 1/1] UIO: Add a write() function to enable/disable interrupts

Leon Woestenberg
2008-05-23T20:44:53Z

Hello,

On Fri, May 23, 2008 at 1:55 PM, Hans J. Koch <hjk@linutronix.de> wrote:
> +static ssize_t uio_write(struct file *filep, const char __user *buf,
> + size_t count, loff_t *ppos)
> +{
> + struct uio_listener *listener = filep->private_data;
> + struct uio_device *idev = listener->dev;
> + ssize_t retval;
> + s32 irq_on;
> +
> + if (idev->info->irq == UIO_IRQ_NONE)
> + return -EIO;
> +
> + if (count != sizeof(s32))
> + return -EINVAL;
> +
> + if (!idev->info->irqcontrol)
> + return -ENOSYS;
> +
> + if (copy_from_user(&irq_on, buf, count))
> + return -EFAULT;
> +
> + retval = idev->info->irqcontrol(idev->info, irq_on);
> +
> + return retval ? retval : sizeof(s32);
> +}
> +

Shouldn't this be more future-proof, what if we need to abuse write()
for something else in the future?

I would suggest a check for ppos to be 0 (zero) as well, just to be
sure and future-proof and backwards-safe.

Regards,
--
Leon