linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] gpiolib: shifters used as flags in gpio_ioctl()
@ 2016-02-23  9:44 Dan Carpenter
  2016-02-23 12:58 ` Linus Walleij
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2016-02-23  9:44 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Alexandre Courbot, linux-gpio, kernel-janitors

We weren't testing whether the bits were set correctly because we used
shifters as flags.  It means that we give the user incorrect line
information in this new ioctl.

Fixes: 521a2ad6f862 ('gpio: add userspace ABI for GPIO line information')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index b816469..d609e03 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -380,17 +380,19 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		 * this GPIO so it can't use it.
 		 */
 		lineinfo.flags = 0;
-		if (desc->flags & (FLAG_REQUESTED | FLAG_IS_HOGGED |
-				   FLAG_USED_AS_IRQ | FLAG_EXPORT |
-				   FLAG_SYSFS))
+		if (desc->flags & ((1 << FLAG_REQUESTED) |
+				   (1 << FLAG_IS_HOGGED) |
+				   (1 << FLAG_USED_AS_IRQ) |
+				   (1 << FLAG_EXPORT) |
+				   (1 << FLAG_SYSFS)))
 			lineinfo.flags |= GPIOLINE_FLAG_KERNEL;
-		if (desc->flags & FLAG_IS_OUT)
+		if (test_bit(FLAG_IS_OUT, &desc->flags))
 			lineinfo.flags |= GPIOLINE_FLAG_IS_OUT;
-		if (desc->flags & FLAG_ACTIVE_LOW)
+		if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
 			lineinfo.flags |= GPIOLINE_FLAG_ACTIVE_LOW;
-		if (desc->flags & FLAG_OPEN_DRAIN)
+		if (test_bit(FLAG_OPEN_DRAIN, &desc->flags))
 			lineinfo.flags |= GPIOLINE_FLAG_OPEN_DRAIN;
-		if (desc->flags & FLAG_OPEN_SOURCE)
+		if (test_bit(FLAG_OPEN_SOURCE, &desc->flags))
 			lineinfo.flags |= GPIOLINE_FLAG_OPEN_SOURCE;
 
 		if (copy_to_user(ip, &lineinfo, sizeof(lineinfo)))

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [patch] gpiolib: shifters used as flags in gpio_ioctl()
  2016-02-23  9:44 [patch] gpiolib: shifters used as flags in gpio_ioctl() Dan Carpenter
@ 2016-02-23 12:58 ` Linus Walleij
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2016-02-23 12:58 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Alexandre Courbot, linux-gpio@vger.kernel.org, kernel-janitors

On Tue, Feb 23, 2016 at 10:44 AM, Dan Carpenter
<dan.carpenter@oracle.com> wrote:

> We weren't testing whether the bits were set correctly because we used
> shifters as flags.  It means that we give the user incorrect line
> information in this new ioctl.
>
> Fixes: 521a2ad6f862 ('gpio: add userspace ABI for GPIO line information')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Already wrote and queued a similar patch yesterday, but thanks anyway Dan!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-23 12:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-23  9:44 [patch] gpiolib: shifters used as flags in gpio_ioctl() Dan Carpenter
2016-02-23 12:58 ` Linus Walleij

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).