]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gpiolib: handle gpio-hogs only once
authorDaniel Drake <dan@reactivated.net>
Mon, 8 Jun 2026 21:01:08 +0000 (22:01 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Wed, 10 Jun 2026 08:12:57 +0000 (10:12 +0200)
Commit d1d564ec49929 ("gpio: move hogs into GPIO core") introduced a
behaviour change that breaks boot on Raspberry Pi 5 when using the
firmware-supplied device tree:

  gpiochip_add_data_with_key: GPIOs 544..575
    (/soc@107c000000/gpio@7d517c00) failed to register, -22
  brcmstb-gpio 107d517c00.gpio: Could not add gpiochip for bank 1
  brcmstb-gpio 107d517c00.gpio: probe with driver brcmstb-gpio failed
    with error -22

gpio-brcmstb registers two gpio_chips against the device tree
node gpio@7d517c00, one for each bank. The firmware-supplied DT includes
a gpio-hog on RP1 RUN, and this gpio-hog is attempted to be applied to
*both* gpio_chips. This succeeds against bank 0 (which hosts the GPIO)
and fails for bank 1 (which does not).

In the previous implementation, failures to apply gpio-hogs were
quietly ignored. In the new code, the error code propagates and causes
probe to fail.

Closely approximate the previous behaviour by using the OF_POPULATED flag
to ensure that each gpio-hog is processed only once. The flag was
previously being set before the gpio-hogs were processed, so as part
of this change, the flag now gets set only after the gpio-hog is actioned.
The handling of gpio-hogs on a DT node with multiple gpio_chips remains a
bit incomplete/unclear, but this at least retains the ability to apply
hogs to the first gpio_chip per node.

Fixes: d1d564ec49929 ("gpio: move hogs into GPIO core")
Signed-off-by: Daniel Drake <dan@reactivated.net>
Link: https://patch.msgid.link/20260608210108.36248-1-dan@reactivated.net
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
drivers/gpio/gpiolib-of.c
drivers/gpio/gpiolib.c

index 2c923d17541f26586d531713d7f1fc917cdceaf4..813dbcb91f6fa6a7e8bd669f7310e6590b93abad 100644 (file)
@@ -1066,11 +1066,6 @@ int of_gpiochip_add(struct gpio_chip *chip)
 
        of_node_get(np);
 
-       for_each_available_child_of_node_scoped(np, child) {
-               if (of_property_read_bool(child, "gpio-hog"))
-                       of_node_set_flag(child, OF_POPULATED);
-       }
-
        return ret;
 }
 
index d3e0d77f74e7ae23d496ea0ef04dbf0beec4ec17..c1f9c0d367d5c203849247d411576242ca74b8b3 100644 (file)
@@ -1031,9 +1031,17 @@ static int gpiochip_hog_lines(struct gpio_chip *gc)
                if (!fwnode_property_present(fwnode, "gpio-hog"))
                        continue;
 
+               /* The hog may have been handled by another gpio_chip on the same fwnode */
+               if (is_of_node(fwnode) &&
+                   of_node_check_flag(to_of_node(fwnode), OF_POPULATED))
+                       continue;
+
                ret = gpiochip_add_hog(gc, fwnode);
                if (ret)
                        return ret;
+
+               if (is_of_node(fwnode))
+                       of_node_set_flag(to_of_node(fwnode), OF_POPULATED);
        }
 
        return 0;