[PATCH v4 1/6] gpio: Access `gpio_bus_type` in gpiochip_setup_dev()

From: Tzung-Bi Shih

Date: Mon Feb 23 2026 - 01:18:14 EST


To make the intent clear, access `gpio_bus_type` only when it's ready in
gpiochip_setup_dev().

Reviewed-by: Linus Walleij <linusw@xxxxxxxxxx>
Signed-off-by: Tzung-Bi Shih <tzungbi@xxxxxxxxxx>
---
v4:
- Add R-b tag.

v3: https://lore.kernel.org/all/20260213092958.864411-2-tzungbi@xxxxxxxxxx
- No changes.

v2: https://lore.kernel.org/all/20260203061059.975605-2-tzungbi@xxxxxxxxxx
- No changes.

v1: https://lore.kernel.org/all/20260116081036.352286-7-tzungbi@xxxxxxxxxx

drivers/gpio/gpiolib.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index f77d5121a8a8..0a73561060dd 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -901,6 +901,8 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev);
int ret;

+ gdev->dev.bus = &gpio_bus_type;
+
/*
* If fwnode doesn't belong to another device, it's safe to clear its
* initialized flag.
@@ -1082,7 +1084,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
* then make sure they get free():ed there.
*/
gdev->dev.type = &gpio_dev_type;
- gdev->dev.bus = &gpio_bus_type;
gdev->dev.parent = gc->parent;
device_set_node(&gdev->dev, gpiochip_choose_fwnode(gc));

@@ -1220,8 +1221,8 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
* we get a device node entry in sysfs under
* /sys/bus/gpio/devices/gpiochipN/dev that can be used for
* coldplug of device nodes and other udev business.
- * We can do this only if gpiolib has been initialized.
- * Otherwise, defer until later.
+ * We can do this only if gpiolib has been initialized
+ * (i.e., `gpio_bus_type` is ready). Otherwise, defer until later.
*/
if (gpiolib_initialized) {
ret = gpiochip_setup_dev(gdev);
--
2.51.0