gpio: Access gpio_bus_type in gpiochip_setup_dev()

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

Reviewed-by: Linus Walleij <linusw@kernel.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://patch.msgid.link/20260223061726.82161-2-tzungbi@kernel.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
This commit is contained in:
Tzung-Bi Shih 2026-02-23 14:17:21 +08:00 committed by Bartosz Golaszewski
parent b08b3f16bb
commit cc11f4ef66

View File

@ -902,6 +902,8 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev); struct fwnode_handle *fwnode = dev_fwnode(&gdev->dev);
int ret; int ret;
gdev->dev.bus = &gpio_bus_type;
/* /*
* If fwnode doesn't belong to another device, it's safe to clear its * If fwnode doesn't belong to another device, it's safe to clear its
* initialized flag. * initialized flag.
@ -1083,7 +1085,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
* then make sure they get free():ed there. * then make sure they get free():ed there.
*/ */
gdev->dev.type = &gpio_dev_type; gdev->dev.type = &gpio_dev_type;
gdev->dev.bus = &gpio_bus_type;
gdev->dev.parent = gc->parent; gdev->dev.parent = gc->parent;
device_set_node(&gdev->dev, gpiochip_choose_fwnode(gc)); device_set_node(&gdev->dev, gpiochip_choose_fwnode(gc));
@ -1221,8 +1222,8 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
* we get a device node entry in sysfs under * we get a device node entry in sysfs under
* /sys/bus/gpio/devices/gpiochipN/dev that can be used for * /sys/bus/gpio/devices/gpiochipN/dev that can be used for
* coldplug of device nodes and other udev business. * coldplug of device nodes and other udev business.
* We can do this only if gpiolib has been initialized. * We can do this only if gpiolib has been initialized
* Otherwise, defer until later. * (i.e., `gpio_bus_type` is ready). Otherwise, defer until later.
*/ */
if (gpiolib_initialized) { if (gpiolib_initialized) {
ret = gpiochip_setup_dev(gdev); ret = gpiochip_setup_dev(gdev);