summaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib-sysfs.c
diff options
context:
space:
mode:
authorChristophe Leroy <christophe.leroy@c-s.fr>2017-12-18 11:08:31 +0100
committerLinus Walleij <linus.walleij@linaro.org>2017-12-20 10:33:21 +0100
commit9295c01253b4eda5dc0b5a5b2e0fd321fe57010c (patch)
tree779f856770f7759d7f15bd29c9717e44208be691 /drivers/gpio/gpiolib-sysfs.c
parentgpio: sysfs: change 'value' attribute to prealloc (diff)
downloadlinux-9295c01253b4eda5dc0b5a5b2e0fd321fe57010c.tar.xz
linux-9295c01253b4eda5dc0b5a5b2e0fd321fe57010c.zip
gpio: sysfs: correct error handling on 'value' attribute read.
'value' attribute is supposed to only return 0 or 1 according to the documentation. With today's implementation, if gpiod_get_value_cansleep() fails the printed 'value' is a negative value. This patch ensures that an error is returned on read instead. Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpiolib-sysfs.c')
-rw-r--r--drivers/gpio/gpiolib-sysfs.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 3b2465bbd5e7..ef34b8f56bd1 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -106,8 +106,12 @@ static ssize_t value_show(struct device *dev,
mutex_lock(&data->mutex);
- status = sprintf(buf, "%d\n", gpiod_get_value_cansleep(desc));
+ status = gpiod_get_value_cansleep(desc);
+ if (status < 0)
+ goto err;
+ status = sprintf(buf, "%d\n", status);
+err:
mutex_unlock(&data->mutex);
return status;