Skip to contentSkip to conversation

gpiolib: clear requested flag if line is invalid

PATCH Applied Barnabás Pőcze 3 participants 3 messages Mar 10 – Mar 11 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: clear requested flag if line is invalid

If gpiochip_line_is_valid() fails, then -EINVAL is returned, but desc->flags will have GPIOD_FLAG_REQUESTED set, which will result in subsequent calls misleadingly returning -EBUSY.

Fix that by clearing the flag in case of failure.

Fixes a501624864f3 ("gpio: Respect valid_mask when requesting GPIOs")
---
 drivers/gpio/gpiolib.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib.c +4 -2
index ada572aaebd6..9550500e1690 100644
@@ -2465,8 +2465,10 @@ int gpiod_request_commit(struct gpio_desc *desc, const char *label)
 		return -EBUSY;
 
 	offset = gpiod_hwgpio(desc);
-	if (!gpiochip_line_is_valid(guard.gc, offset))
-		return -EINVAL;
+	if (!gpiochip_line_is_valid(guard.gc, offset)) {
+		ret = -EINVAL;
+		goto out_clear_bit;
+	}
 
 	/* NOTE:  gpio_request() can be called in early boot,
 	 * before IRQs are enabled, for non-sleeping (SOC) GPIOs.
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw

Hi!

Well spotted, thanks!

Quoted 8 lines · Barnabás Pőcze

If gpiochip_line_is_valid() fails, then -EINVAL is returned, but desc->flags will have GPIOD_FLAG_REQUESTED set, which will result in subsequent calls misleadingly returning -EBUSY.

Fix that by clearing the flag in case of failure.

Fixes a501624864f3 ("gpio: Respect valid_mask when requesting GPIOs")

---
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~

#2 lore raw
In reply to Barnabás Pőcze
Quoted 8 lines · Barnabás Pőcze

If gpiochip_line_is_valid() fails, then -EINVAL is returned, but desc->flags will have GPIOD_FLAG_REQUESTED set, which will result in subsequent calls misleadingly returning -EBUSY.

Fix that by clearing the flag in case of failure.

[...]

Applied, thanks!

[1/1] gpiolib: clear requested flag if line is invalid

      https://git.kernel.org/brgl/c/6df6ea4b3d1567dbe6442f308735c23b63007c7f

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>