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>
This commit is contained in:
Bartosz Golaszewski 2017-06-09 13:41:26 +02:00 committed by Linus Walleij
parent 6f9b3e776d
commit 650b57b083

View File

@ -210,24 +210,23 @@ static ssize_t gpio_mockup_event_write(struct file *file,
struct gpio_chip *gc; struct gpio_chip *gc;
int rv, val; 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); rv = kstrtoint_from_user(usr_buf, size, 0, &val);
if (rv) if (rv)
return rv; return rv;
if (val != 0 && val != 1) if (val != 0 && val != 1)
return -EINVAL; return -EINVAL;
if (!chip->lines[priv->offset].irq_enabled) sfile = file->private_data;
return size; priv = sfile->private;
desc = priv->desc;
chip = priv->chip;
gc = &chip->gc;
gpiod_set_value_cansleep(desc, val); if (chip->lines[priv->offset].irq_enabled) {
priv->chip->irq_ctx.irq = gc->irq_base + priv->offset; gpiod_set_value_cansleep(desc, val);
irq_work_queue(&priv->chip->irq_ctx.work); priv->chip->irq_ctx.irq = gc->irq_base + priv->offset;
irq_work_queue(&priv->chip->irq_ctx.work);
}
return size; return size;
} }