summaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorMarc Zyngier <maz@kernel.org>2020-12-04 16:47:36 +0000
committerLinus Walleij <linus.walleij@linaro.org>2020-12-09 10:23:04 +0100
commita0db197f534fb24d64cc8c716b5f128f2de1c898 (patch)
tree58e7c356f9718b56098f84176b2e804be24b3ba0 /drivers/gpio
parent37ddba0245b4547621862c0b24bf36deb199bf5c (diff)
downloadlinux-a0db197f534fb24d64cc8c716b5f128f2de1c898.tar.gz
linux-a0db197f534fb24d64cc8c716b5f128f2de1c898.tar.bz2
linux-a0db197f534fb24d64cc8c716b5f128f2de1c898.zip
gpiolib: cdev: Flag invalid GPIOs as used
When reporting the state of a GPIO to userspace, we never check for the actual validity of the line, meaning we report invalid lines as being usable. A subsequent request will fail though, which is an inconsistent behaviour from a userspace perspective. Instead, let's check for the validity of the line and report it as used if it is invalid. This allows a tool such as gpioinfo to report something sensible: gpiochip3 - 4 lines: line 0: unnamed unused input active-high line 1: unnamed kernel input active-high [used] line 2: unnamed kernel input active-high [used] line 3: unnamed unused input active-high In this example, lines 1 and 2 are invalid, and cannot be used by userspace. Signed-off-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20201204164739.781812-2-maz@kernel.org Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpiolib-cdev.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index f64a35767434..bd40d717765c 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -1914,6 +1914,7 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,
test_bit(FLAG_USED_AS_IRQ, &desc->flags) ||
test_bit(FLAG_EXPORT, &desc->flags) ||
test_bit(FLAG_SYSFS, &desc->flags) ||
+ !gpiochip_line_is_valid(gc, info->offset) ||
!ok_for_pinctrl)
info->flags |= GPIO_V2_LINE_FLAG_USED;