Skip to content

Commit 3518fd4

Browse files
Tzung-Bi ShihBartosz Golaszewski
authored andcommitted
Revert "gpio: Access gpio_bus_type in gpiochip_setup_dev()"
This reverts commit cc11f4e. Commit cc11f4e ("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>
1 parent 7673e4c commit 3518fd4

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

drivers/gpio/gpiolib.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,6 @@ static int gpiochip_setup_dev(struct gpio_chip *gc)
908908
struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev);
909909
int ret;
910910

911-
gdev->dev.bus = &gpio_bus_type;
912-
913911
/*
914912
* If fwnode doesn't belong to another device, it's safe to clear its
915913
* initialized flag.
@@ -1160,6 +1158,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
11601158
* then make sure they get free():ed there.
11611159
*/
11621160
gdev->dev.type = &gpio_dev_type;
1161+
gdev->dev.bus = &gpio_bus_type;
11631162
gdev->dev.parent = gc->parent;
11641163
device_set_node(&gdev->dev, gpiochip_choose_fwnode(gc));
11651164

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

0 commit comments

Comments
 (0)