Message ID | b9e7fbdb52adee6602b86e0771c6e26f35e21ac4.1513591276.git.christophe.leroy@c-s.fr |
---|---|
State | New |
Headers | show |
Series | [1/4] gpio: sysfs: change 'value' attribute to prealloc | expand |
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 7a3f4271393b..1b0f415df03b 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;
'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> --- drivers/gpio/gpiolib-sysfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)