summaryrefslogtreecommitdiff
path: root/drivers/gpio/gpio-mockup.c
diff options
context:
space:
mode:
authorBartosz Golaszewski <brgl@bgdev.pl>2017-06-09 13:41:26 +0200
committerLinus Walleij <linus.walleij@linaro.org>2017-06-20 09:18:47 +0200
commit650b57b083ef22208c1d10e554f964571221bca4 (patch)
tree801d35df9e34746aaa80dea835ddeae2d60d2853 /drivers/gpio/gpio-mockup.c
parent6f9b3e776d171636ccafbcb39a8210b4fa37136b (diff)
downloadlwn-650b57b083ef22208c1d10e554f964571221bca4.tar.gz
lwn-650b57b083ef22208c1d10e554f964571221bca4.zip
gpio: mockup: tweak gpio_mockup_event_write()
Invert the logic of the irq_enabled check and only access the private data after the input is sanitized. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpio-mockup.c')
-rw-r--r--drivers/gpio/gpio-mockup.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index da76267aa85c..d78e8e081f5a 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -210,24 +210,23 @@ static ssize_t gpio_mockup_event_write(struct file *file,
struct gpio_chip *gc;
int rv, val;
- sfile = file->private_data;
- priv = sfile->private;
- desc = priv->desc;
- chip = priv->chip;
- gc = &chip->gc;
-
rv = kstrtoint_from_user(usr_buf, size, 0, &val);
if (rv)
return rv;
if (val != 0 && val != 1)
return -EINVAL;
- if (!chip->lines[priv->offset].irq_enabled)
- return size;
+ sfile = file->private_data;
+ priv = sfile->private;
+ desc = priv->desc;
+ chip = priv->chip;
+ gc = &chip->gc;
- gpiod_set_value_cansleep(desc, val);
- priv->chip->irq_ctx.irq = gc->irq_base + priv->offset;
- irq_work_queue(&priv->chip->irq_ctx.work);
+ if (chip->lines[priv->offset].irq_enabled) {
+ gpiod_set_value_cansleep(desc, val);
+ priv->chip->irq_ctx.irq = gc->irq_base + priv->offset;
+ irq_work_queue(&priv->chip->irq_ctx.work);
+ }
return size;
}