linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-gpio@vger.kernel.org, Alexandre Courbot <acourbot@nvidia.com>
Subject: Re: [PATCH] gpio: handle compatible ioctl() pointers
Date: Fri, 27 May 2016 10:22:22 -0700	[thread overview]
Message-ID: <20160527172222.GB25540@dtor-ws> (raw)
In-Reply-To: <1464352373-25108-1-git-send-email-linus.walleij@linaro.org>

On Fri, May 27, 2016 at 02:32:53PM +0200, Linus Walleij wrote:
> If we're using the compatible ioctl() we need to handle the
> argument pointer in a special way or there will be trouble.
> 
> Fixes: 3c702e9987e2 ("gpio: add a userspace chardev ABI for GPIOs")
> Reported-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

> ---
>  drivers/gpio/gpiolib.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index e901d2666b46..f1ef27014e6e 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -20,6 +20,7 @@
>  #include <linux/cdev.h>
>  #include <linux/fs.h>
>  #include <linux/uaccess.h>
> +#include <linux/compat.h>
>  #include <uapi/linux/gpio.h>
>  
>  #include "gpiolib.h"
> @@ -316,7 +317,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  {
>  	struct gpio_device *gdev = filp->private_data;
>  	struct gpio_chip *chip = gdev->chip;
> -	int __user *ip = (int __user *)arg;
> +	void __user *ip = (void __user *)arg;
>  
>  	/* We fail any subsequent ioctl():s when the chip is gone */
>  	if (!chip)
> @@ -388,6 +389,14 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  	return -EINVAL;
>  }
>  
> +#ifdef CONFIG_COMPAT
> +static long gpio_ioctl_compat(struct file *filp, unsigned int cmd,
> +			      unsigned long arg)
> +{
> +	return gpio_ioctl(filep, cmd, (unsigned long)compat_ptr(arg));
> +}
> +#endif
> +
>  /**
>   * gpio_chrdev_open() - open the chardev for ioctl operations
>   * @inode: inode for this chardev
> @@ -431,7 +440,9 @@ static const struct file_operations gpio_fileops = {
>  	.owner = THIS_MODULE,
>  	.llseek = noop_llseek,
>  	.unlocked_ioctl = gpio_ioctl,
> -	.compat_ioctl = gpio_ioctl,
> +#ifdef CONFIG_COMPAT
> +	.compat_ioctl = gpio_ioctl_compat,
> +#endif
>  };
>  
>  static void gpiodevice_release(struct device *dev)
> -- 
> 2.4.11
> 

-- 
Dmitry

      reply	other threads:[~2016-05-27 17:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-27 12:32 [PATCH] gpio: handle compatible ioctl() pointers Linus Walleij
2016-05-27 17:22 ` Dmitry Torokhov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160527172222.GB25540@dtor-ws \
    --to=dmitry.torokhov@gmail.com \
    --cc=acourbot@nvidia.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).