[PATCH 5.16 0018/1017] Revert "gpio: Revert regression in sysfs-gpio (gpiolib.c)"

From: Greg Kroah-Hartman
Date: Tue Apr 05 2022 - 06:51:06 EST


From: Bartosz Golaszewski <brgl@xxxxxxxx>

[ Upstream commit 56e337f2cf1326323844927a04e9dbce9a244835 ]

This reverts commit fc328a7d1fcce263db0b046917a66f3aa6e68719.

This commit - while attempting to fix a regression - has caused a number
of other problems. As the fallout from it is more significant than the
initial problem itself, revert it for now before we find a correct
solution.

Link: https://lore.kernel.org/all/20220314192522.GA3031157@xxxxxxxxxxxx/
Link: https://lore.kernel.org/stable/20220314155509.552218-1-michael@xxxxxxxx/
Link: https://lore.kernel.org/all/20211217153555.9413-1-marcelo.jimenez@xxxxxxxxx/
Signed-off-by: Bartosz Golaszewski <brgl@xxxxxxxx>
Reported-and-bisected-by: Guenter Roeck <linux@xxxxxxxxxxxx>
Reported-by: Michael Walle <michael@xxxxxxxx>
Cc: Thorsten Leemhuis <linux@xxxxxxxxxxxxx>
Cc: Marcelo Roberto Jimenez <marcelo.jimenez@xxxxxxxxx>
Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
drivers/gpio/gpiolib.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 1c73e4cfe80e..dcb0dca651ac 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1665,6 +1665,11 @@ static inline void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc)
*/
int gpiochip_generic_request(struct gpio_chip *gc, unsigned int offset)
{
+#ifdef CONFIG_PINCTRL
+ if (list_empty(&gc->gpiodev->pin_ranges))
+ return 0;
+#endif
+
return pinctrl_gpio_request(gc->gpiodev->base + offset);
}
EXPORT_SYMBOL_GPL(gpiochip_generic_request);
@@ -1676,6 +1681,11 @@ EXPORT_SYMBOL_GPL(gpiochip_generic_request);
*/
void gpiochip_generic_free(struct gpio_chip *gc, unsigned int offset)
{
+#ifdef CONFIG_PINCTRL
+ if (list_empty(&gc->gpiodev->pin_ranges))
+ return;
+#endif
+
pinctrl_gpio_free(gc->gpiodev->base + offset);
}
EXPORT_SYMBOL_GPL(gpiochip_generic_free);
--
2.34.1