[PATCH] gpiolib: tolerate gpio-hogs lacking a hogging state

Daniel Golle posted 1 patch 1 week, 4 days ago
drivers/gpio/gpiolib.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
[PATCH] gpiolib: tolerate gpio-hogs lacking a hogging state
Posted by Daniel Golle 1 week, 4 days ago
Commit d1d564ec4992 ("gpio: move hogs into GPIO core") made
gpiochip_add_hog() return -EINVAL for hog nodes lacking any of the
'input', 'output-low' or 'output-high' properties. The error is
propagated by gpiochip_hog_lines() and fails registration of the
whole GPIO chip.

The previous OF-specific implementation tolerated such nodes:
of_parse_own_gpio() warned "no hogging state specified, bailing out"
and of_gpiochip_add_hog() stopped processing the node without failing
chip registration.

Some boards deliberately ship hog nodes without a hogging state in
their base devicetree and supply the state via overlay, e.g. the PCIe
slot key selection hogs on the BananaPi R4 Pro added in
commit e309fa232d12 ("arm64: dts: mediatek: mt7988a-bpi-r4pro: rework
pcie gpio-hog handling"), as the polarity set in the base devicetree
could not be overridden from an overlay.

Booting such a board without an overlay applied now fails to register
the gpiochip. On the BananaPi R4 Pro this means the MT7988A pinctrl
device fails to probe, all peripherals including the console UART
defer forever, and the board finally hangs when clk_disable_unused()
gates the clocks of the UART still in use by earlycon:

  gpiochip_add_data_with_key: GPIOs 512..595 (pinctrl_moore) failed to register, -22
  mt7988-pinctrl 1001f000.pinctrl: error -EINVAL: Failed to add gpio_chip
  ...
  clk: Disabling unused clocks
  (hangs)

Restore the previous behaviour by warning about hog nodes lacking a
hogging state and skipping them instead of failing the registration
of the whole GPIO chip.

Fixes: d1d564ec4992 ("gpio: move hogs into GPIO core")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 drivers/gpio/gpiolib.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index e5fb60111151..c433a095907f 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -999,14 +999,17 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
 	if (ret < 0)
 		return ret;
 
-	if (fwnode_property_present(fwnode, "input"))
+	if (fwnode_property_present(fwnode, "input")) {
 		dflags |= GPIOD_IN;
-	else if (fwnode_property_present(fwnode, "output-low"))
+	} else if (fwnode_property_present(fwnode, "output-low")) {
 		dflags |= GPIOD_OUT_LOW;
-	else if (fwnode_property_present(fwnode, "output-high"))
+	} else if (fwnode_property_present(fwnode, "output-high")) {
 		dflags |= GPIOD_OUT_HIGH;
-	else
-		return -EINVAL;
+	} else {
+		gpiochip_warn(gc, "%pfwP: no hogging state specified, bailing out\n",
+			      fwnode);
+		return 0;
+	}
 
 	fwnode_property_read_string(fwnode, "line-name", &name);
 
-- 
2.55.0
Re: [PATCH] gpiolib: tolerate gpio-hogs lacking a hogging state
Posted by Bartosz Golaszewski 1 week, 3 days ago
On Tue, 14 Jul 2026 00:30:53 +0100, Daniel Golle wrote:
> Commit d1d564ec4992 ("gpio: move hogs into GPIO core") made
> gpiochip_add_hog() return -EINVAL for hog nodes lacking any of the
> 'input', 'output-low' or 'output-high' properties. The error is
> propagated by gpiochip_hog_lines() and fails registration of the
> whole GPIO chip.
> 
> The previous OF-specific implementation tolerated such nodes:
> of_parse_own_gpio() warned "no hogging state specified, bailing out"
> and of_gpiochip_add_hog() stopped processing the node without failing
> chip registration.
> 
> [...]

Applied, thanks!

[1/1] gpiolib: tolerate gpio-hogs lacking a hogging state
      https://git.kernel.org/brgl/c/e1cc8fa0fb9e5112d15f2c310b68ac316981c06c

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Re: [PATCH] gpiolib: tolerate gpio-hogs lacking a hogging state
Posted by Andy Shevchenko 1 week, 4 days ago
On Tue, Jul 14, 2026 at 12:30:53AM +0100, Daniel Golle wrote:
> Commit d1d564ec4992 ("gpio: move hogs into GPIO core") made
> gpiochip_add_hog() return -EINVAL for hog nodes lacking any of the
> 'input', 'output-low' or 'output-high' properties. The error is
> propagated by gpiochip_hog_lines() and fails registration of the
> whole GPIO chip.
> 
> The previous OF-specific implementation tolerated such nodes:
> of_parse_own_gpio() warned "no hogging state specified, bailing out"
> and of_gpiochip_add_hog() stopped processing the node without failing
> chip registration.
> 
> Some boards deliberately ship hog nodes without a hogging state in
> their base devicetree and supply the state via overlay, e.g. the PCIe
> slot key selection hogs on the BananaPi R4 Pro added in
> commit e309fa232d12 ("arm64: dts: mediatek: mt7988a-bpi-r4pro: rework
> pcie gpio-hog handling"), as the polarity set in the base devicetree
> could not be overridden from an overlay.
> 
> Booting such a board without an overlay applied now fails to register
> the gpiochip. On the BananaPi R4 Pro this means the MT7988A pinctrl
> device fails to probe, all peripherals including the console UART
> defer forever, and the board finally hangs when clk_disable_unused()
> gates the clocks of the UART still in use by earlycon:
> 
>   gpiochip_add_data_with_key: GPIOs 512..595 (pinctrl_moore) failed to register, -22
>   mt7988-pinctrl 1001f000.pinctrl: error -EINVAL: Failed to add gpio_chip
>   ...
>   clk: Disabling unused clocks
>   (hangs)
> 
> Restore the previous behaviour by warning about hog nodes lacking a
> hogging state and skipping them instead of failing the registration
> of the whole GPIO chip.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

...

> -	if (fwnode_property_present(fwnode, "input"))
> +	if (fwnode_property_present(fwnode, "input")) {
>  		dflags |= GPIOD_IN;
> -	else if (fwnode_property_present(fwnode, "output-low"))
> +	} else if (fwnode_property_present(fwnode, "output-low")) {
>  		dflags |= GPIOD_OUT_LOW;
> -	else if (fwnode_property_present(fwnode, "output-high"))
> +	} else if (fwnode_property_present(fwnode, "output-high")) {
>  		dflags |= GPIOD_OUT_HIGH;

For a fix I would make it less invasive and yes, break the style, by just
replacing

> -	else
> -		return -EINVAL;

with

	else {
		gpiochip_warn(gc, "%pfwP: no hogging state specified, bailing out\n",
			      fwnode);
		return 0;
	}

> +	} else {
> +		gpiochip_warn(gc, "%pfwP: no hogging state specified, bailing out\n",
> +			      fwnode);
> +		return 0;
> +	}

This leads patch directly to the point. The style can be modified later on.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH] gpiolib: tolerate gpio-hogs lacking a hogging state
Posted by Bartosz Golaszewski 1 week, 3 days ago
On Tue, 14 Jul 2026 10:45:48 +0200, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> said:
> On Tue, Jul 14, 2026 at 12:30:53AM +0100, Daniel Golle wrote:
>> Commit d1d564ec4992 ("gpio: move hogs into GPIO core") made
>> gpiochip_add_hog() return -EINVAL for hog nodes lacking any of the
>> 'input', 'output-low' or 'output-high' properties. The error is
>> propagated by gpiochip_hog_lines() and fails registration of the
>> whole GPIO chip.
>>
>> The previous OF-specific implementation tolerated such nodes:
>> of_parse_own_gpio() warned "no hogging state specified, bailing out"
>> and of_gpiochip_add_hog() stopped processing the node without failing
>> chip registration.
>>
>> Some boards deliberately ship hog nodes without a hogging state in
>> their base devicetree and supply the state via overlay, e.g. the PCIe
>> slot key selection hogs on the BananaPi R4 Pro added in
>> commit e309fa232d12 ("arm64: dts: mediatek: mt7988a-bpi-r4pro: rework
>> pcie gpio-hog handling"), as the polarity set in the base devicetree
>> could not be overridden from an overlay.
>>
>> Booting such a board without an overlay applied now fails to register
>> the gpiochip. On the BananaPi R4 Pro this means the MT7988A pinctrl
>> device fails to probe, all peripherals including the console UART
>> defer forever, and the board finally hangs when clk_disable_unused()
>> gates the clocks of the UART still in use by earlycon:
>>
>>   gpiochip_add_data_with_key: GPIOs 512..595 (pinctrl_moore) failed to register, -22
>>   mt7988-pinctrl 1001f000.pinctrl: error -EINVAL: Failed to add gpio_chip
>>   ...
>>   clk: Disabling unused clocks
>>   (hangs)
>>
>> Restore the previous behaviour by warning about hog nodes lacking a
>> hogging state and skipping them instead of failing the registration
>> of the whole GPIO chip.
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> ...
>
>> -	if (fwnode_property_present(fwnode, "input"))
>> +	if (fwnode_property_present(fwnode, "input")) {
>>  		dflags |= GPIOD_IN;
>> -	else if (fwnode_property_present(fwnode, "output-low"))
>> +	} else if (fwnode_property_present(fwnode, "output-low")) {
>>  		dflags |= GPIOD_OUT_LOW;
>> -	else if (fwnode_property_present(fwnode, "output-high"))
>> +	} else if (fwnode_property_present(fwnode, "output-high")) {
>>  		dflags |= GPIOD_OUT_HIGH;
>
> For a fix I would make it less invasive and yes, break the style, by just
> replacing
>

Nah, this is fine as is, let me queue this and sorry for the trouble, thanks
for spotting and fixing it!

Bart