Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH] gpiolib: use the of_xlate() result when hogging lines
@ 2026-11-25 15:03 Bartosz Golaszewski
  2026-11-25 17:28 ` Norman Herms
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-11-25 15:03 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Mika Westerberg,
	Andy Shevchenko
  Cc: linux-gpio, stable, Norman Herms, Bartosz Golaszewski

Since commit d1d564ec4992 ("gpio: move hogs into GPIO core"),
gpiochip_add_hog() takes the hogged line from the first cell of the
"gpios" property. The of_xlate() callback is still called for OF nodes
but only to get the flags so on controllers that compute the offset in
of_xlate() (sunxi, Qualcomm PMIC GPIOs, tegra186, ...) the wrong line is
hogged.

Use the descriptor returned by of_xlate() for OF nodes.

Cc: stable@vger.kernel.org
Fixes: d1d564ec4992 ("gpio: move hogs into GPIO core")
Reported-by: Norman Herms <dockseed@proton.me>
Closes: https://lore.kernel.org/all/qh4LV99kGaQYdQuGbsPX4b9Fm6Cip_Ow7ImY4icfwI8IsbMQy_09FovZY82b-_HVkDmR2ELMlKe8bzCuBB5NpaZizoO-s4tc11zAX30FDhw=@proton.me/
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
 drivers/gpio/gpiolib-of.c | 10 +++++-----
 drivers/gpio/gpiolib-of.h | 15 ++++++++-------
 drivers/gpio/gpiolib.c    | 14 +++++++-------
 3 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 8bc4562608e1141983300132b90758ce68d7625d..072f84a83c3c657baebd88694f062849b7526a79 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -749,9 +749,9 @@ struct gpio_desc *of_find_gpio(struct device_node *np, const char *con_id,
 	return desc;
 }
 
-int of_gpiochip_get_lflags(struct gpio_chip *chip,
-			   struct fwnode_reference_args *gpiospec,
-			   unsigned long *lflags)
+struct gpio_desc *of_gpiochip_get_hog_desc(struct gpio_chip *chip,
+					   struct fwnode_reference_args *gpiospec,
+					   unsigned long *lflags)
 {
 	enum of_gpio_flags xlate_flags = 0;
 	struct of_phandle_args args;
@@ -765,11 +765,11 @@ int of_gpiochip_get_lflags(struct gpio_chip *chip,
 
 	desc = of_xlate_and_get_gpiod_flags(chip, &args, &xlate_flags);
 	if (IS_ERR(desc))
-		return PTR_ERR(desc);
+		return desc;
 
 	*lflags = of_convert_gpio_flags(xlate_flags);
 
-	return 0;
+	return desc;
 }
 
 #ifdef CONFIG_OF_DYNAMIC
diff --git a/drivers/gpio/gpiolib-of.h b/drivers/gpio/gpiolib-of.h
index 9ca540d93f93be9c1b4791c7add0936527646849..347b82f9e3ff4dcca6b919c058270cc721c81541 100644
--- a/drivers/gpio/gpiolib-of.h
+++ b/drivers/gpio/gpiolib-of.h
@@ -25,9 +25,9 @@ int of_gpiochip_add(struct gpio_chip *gc);
 void of_gpiochip_remove(struct gpio_chip *gc);
 bool of_gpiochip_instance_match(struct gpio_chip *gc, unsigned int index);
 int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id);
-int of_gpiochip_get_lflags(struct gpio_chip *chip,
-			   struct fwnode_reference_args *gpiospec,
-			   unsigned long *lflags);
+struct gpio_desc *of_gpiochip_get_hog_desc(struct gpio_chip *chip,
+					   struct fwnode_reference_args *gpiospec,
+					   unsigned long *lflags);
 #else
 static inline struct gpio_desc *of_find_gpio(struct device_node *np,
 					     const char *con_id,
@@ -48,11 +48,12 @@ static inline int of_gpio_count(const struct fwnode_handle *fwnode,
 {
 	return -ENOENT;
 }
-static inline int of_gpiochip_get_lflags(struct gpio_chip *chip,
-					 struct fwnode_reference_args *gpiospec,
-					 unsigned long *lflags)
+static inline struct gpio_desc *
+of_gpiochip_get_hog_desc(struct gpio_chip *chip,
+			 struct fwnode_reference_args *gpiospec,
+			 unsigned long *lflags)
 {
-	return -ENOENT;
+	return ERR_PTR(-ENOENT);
 }
 #endif /* CONFIG_OF_GPIO */
 
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index c09342fc52cb7fce163e807ba134ecd0e1389436..889ed7e420c19c9a69c9149ead3ea370d7cbbdea 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1036,9 +1036,9 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
 			for (unsigned int j = 0; j < cells; j++)
 				gpiospec.args[j] = gpios[i * cells + j];
 
-			ret = of_gpiochip_get_lflags(gc, &gpiospec, &lflags);
-			if (ret)
-				return ret;
+			desc = of_gpiochip_get_hog_desc(gc, &gpiospec, &lflags);
+			if (IS_ERR(desc))
+				return PTR_ERR(desc);
 
 			/*
 			 * If no line-name property is present, fall back to the OF
@@ -1054,11 +1054,11 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
 			 */
 			if (cells > 1 && gpios[i * cells + 1])
 				lflags |= GPIO_ACTIVE_LOW;
-		}
 
-		desc = gpiochip_get_desc(gc, gpios[i * cells]);
-		if (IS_ERR(desc))
-			return PTR_ERR(desc);
+			desc = gpiochip_get_desc(gc, gpios[i * cells]);
+			if (IS_ERR(desc))
+				return PTR_ERR(desc);
+		}
 
 		ret = gpiod_hog(desc, name, lflags, dflags);
 		if (ret)

---
base-commit: 3dd8c790a7b7027abdd568e36db5e82ffaea7c77
change-id: 20261125-gpio-three-cell-hog-22742394ea02

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpiolib: use the of_xlate() result when hogging lines
  2026-11-25 15:03 [PATCH] gpiolib: use the of_xlate() result when hogging lines Bartosz Golaszewski
@ 2026-11-25 17:28 ` Norman Herms
  2026-11-25 23:50 ` Linus Walleij
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Norman Herms @ 2026-11-25 17:28 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, Bartosz Golaszewski, Mika Westerberg,
	Andy Shevchenko, linux-gpio, stable

Hi Bartosz,

thanks for the quick fix.

Tested on a Radxa Cubie A7S (Allwinner A733) with v7.3.6 plus our
out-of-tree A733 support patches (none of them touches gpiolib or the
sunxi of_xlate()), with this patch backported (context adjusted, the
+/- lines unchanged). Test DT: a hog on the r_pio with
gpios = <1 4 0> (PM4, input).

With the patch the hog is on line 36 (PM4) in /sys/kernel/debug/gpio
and PM4's function field reads 0 (input). Without it, same tree and
config otherwise, the hog is on line 1 (PL1) and PM4 stays at its
reset value 0xf. In both cases PL1 ends up with the R_I2C0 controller
and the PMIC on that bus probes.

Tested-by: Norman Herms <dockseed@proton.me>

The kernels were built and the measurements taken by an AI agent
(Claude) on my board.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpiolib: use the of_xlate() result when hogging lines
  2026-11-25 15:03 [PATCH] gpiolib: use the of_xlate() result when hogging lines Bartosz Golaszewski
  2026-11-25 17:28 ` Norman Herms
@ 2026-11-25 23:50 ` Linus Walleij
  2026-11-26  5:09 ` Mika Westerberg
  2026-11-26 14:12 ` Bartosz Golaszewski
  3 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2026-11-25 23:50 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Bartosz Golaszewski, Mika Westerberg, Andy Shevchenko, linux-gpio,
	stable, Norman Herms

On Wed, Nov 25, 2026 at 4:03 PM Bartosz Golaszewski
<bartosz.golaszewski@oss.qualcomm.com> wrote:

> Since commit d1d564ec4992 ("gpio: move hogs into GPIO core"),
> gpiochip_add_hog() takes the hogged line from the first cell of the
> "gpios" property. The of_xlate() callback is still called for OF nodes
> but only to get the flags so on controllers that compute the offset in
> of_xlate() (sunxi, Qualcomm PMIC GPIOs, tegra186, ...) the wrong line is
> hogged.
>
> Use the descriptor returned by of_xlate() for OF nodes.
>
> Cc: stable@vger.kernel.org
> Fixes: d1d564ec4992 ("gpio: move hogs into GPIO core")
> Reported-by: Norman Herms <dockseed@proton.me>
> Closes: https://lore.kernel.org/all/qh4LV99kGaQYdQuGbsPX4b9Fm6Cip_Ow7ImY4icfwI8IsbMQy_09FovZY82b-_HVkDmR2ELMlKe8bzCuBB5NpaZizoO-s4tc11zAX30FDhw=@proton.me/
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

Looks right!
Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpiolib: use the of_xlate() result when hogging lines
  2026-11-25 15:03 [PATCH] gpiolib: use the of_xlate() result when hogging lines Bartosz Golaszewski
  2026-11-25 17:28 ` Norman Herms
  2026-11-25 23:50 ` Linus Walleij
@ 2026-11-26  5:09 ` Mika Westerberg
  2026-11-26 14:12 ` Bartosz Golaszewski
  3 siblings, 0 replies; 5+ messages in thread
From: Mika Westerberg @ 2026-11-26  5:09 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, Bartosz Golaszewski, Mika Westerberg,
	Andy Shevchenko, linux-gpio, stable, Norman Herms

On Wed, Nov 25, 2026 at 04:03:41PM +0100, Bartosz Golaszewski wrote:
> Since commit d1d564ec4992 ("gpio: move hogs into GPIO core"),
> gpiochip_add_hog() takes the hogged line from the first cell of the
> "gpios" property. The of_xlate() callback is still called for OF nodes
> but only to get the flags so on controllers that compute the offset in
> of_xlate() (sunxi, Qualcomm PMIC GPIOs, tegra186, ...) the wrong line is
> hogged.
> 
> Use the descriptor returned by of_xlate() for OF nodes.
> 
> Cc: stable@vger.kernel.org
> Fixes: d1d564ec4992 ("gpio: move hogs into GPIO core")
> Reported-by: Norman Herms <dockseed@proton.me>
> Closes: https://lore.kernel.org/all/qh4LV99kGaQYdQuGbsPX4b9Fm6Cip_Ow7ImY4icfwI8IsbMQy_09FovZY82b-_HVkDmR2ELMlKe8bzCuBB5NpaZizoO-s4tc11zAX30FDhw=@proton.me/
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

Reviewed-by: Mika Westerberg <westeri@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpiolib: use the of_xlate() result when hogging lines
  2026-11-25 15:03 [PATCH] gpiolib: use the of_xlate() result when hogging lines Bartosz Golaszewski
                   ` (2 preceding siblings ...)
  2026-11-26  5:09 ` Mika Westerberg
@ 2026-11-26 14:12 ` Bartosz Golaszewski
  3 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-11-26 14:12 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Mika Westerberg,
	Andy Shevchenko, Bartosz Golaszewski
  Cc: linux-gpio, stable, Norman Herms


On Wed, 25 Nov 2026 16:03:41 +0100, Bartosz Golaszewski wrote:
> Since commit d1d564ec4992 ("gpio: move hogs into GPIO core"),
> gpiochip_add_hog() takes the hogged line from the first cell of the
> "gpios" property. The of_xlate() callback is still called for OF nodes
> but only to get the flags so on controllers that compute the offset in
> of_xlate() (sunxi, Qualcomm PMIC GPIOs, tegra186, ...) the wrong line is
> hogged.
> 
> [...]

Applied, thanks!

[1/1] gpiolib: use the of_xlate() result when hogging lines
      https://git.kernel.org/brgl/c/64b7a47c24cd1fa01fd7e70bdfd72ea95c8c8e60

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-26 14:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 15:03 [PATCH] gpiolib: use the of_xlate() result when hogging lines Bartosz Golaszewski
2026-11-25 17:28 ` Norman Herms
2026-11-25 23:50 ` Linus Walleij
2026-11-26  5:09 ` Mika Westerberg
2026-11-26 14:12 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox