]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Revert "gpio: Access `gpio_bus_type` in gpiochip_setup_dev()"
authorTzung-Bi Shih <tzungbi@kernel.org>
Fri, 13 Mar 2026 05:41:12 +0000 (05:41 +0000)
committerBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Mon, 16 Mar 2026 09:10:02 +0000 (10:10 +0100)
This reverts commit cc11f4ef666fbca02c8a2f11d0184d57e6b75579.

Commit cc11f4ef666f ("gpio: Access `gpio_bus_type` in
gpiochip_setup_dev()") moved the bus type assignment from
gpiochip_add_data_with_key() to gpiochip_setup_dev().

This change introduced a bug where dev_printk() and friends might access
the bus name after gpiochip_add_data_with_key() but before
gpiochip_setup_dev() has run.  In this window, the bus type is not yet
initialized, leading to empty bus names in logs.

Move the bus type assignment back to gpiochip_add_data_with_key() to
ensure the bus name is available before any potential users like
dev_printk().

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Closes: https://lore.kernel.org/all/CAMuHMdU0Xb=Moca5LUex+VxyHQa2-uYJgYf4hzHiSEjDCQQT=Q@mail.gmail.com/
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://patch.msgid.link/20260313054112.1248074-1-tzungbi@kernel.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
drivers/gpio/gpiolib.c

index e287ab0d21fc40c1e172528210a85d28f686a9f6..9130f2e001acdaea1a7cd47001f390a296953856 100644 (file)
@@ -908,8 +908,6 @@ static int gpiochip_setup_dev(struct gpio_chip *gc)
        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.
@@ -1160,6 +1158,7 @@ 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));
 
@@ -1299,8 +1298,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
-        * (i.e., `gpio_bus_type` is ready).  Otherwise, defer until later.
+        * We can do this only if gpiolib has been initialized.
+        * Otherwise, defer until later.
         */
        if (gpiolib_initialized) {
                ret = gpiochip_setup_dev(gc);