gpiolib: Fix triggering "kobject: 'gpiochipX' is not initialized, yet" kobject_get() errors
Subsystems (2)
PATCH v2 1/1 gpiolib: Fix triggering "kobject: 'gpiochipX' is not initialized, yet" kobject_get() errors
When a gpiochip gets added by loading a module, then another driver may be waiting for that gpiochip to load on the deferred-probe list.
If the deferred-probe for the consumer of gpiochip then triggers between the gpiodev_add_to_list_unlocked() calls which makes gpio_device_find() see the chip and the gpiochip_setup_dev() later then gpio_device_find() does a kobject_get() on an uninitialzed kobject since the kobject is initialized by gpiochip_setup_dev() calling device_initialize():
arizona spi-10WM5102:00: cannot find GPIO chip arizona, deferring arizona spi-10WM5102:00: cannot find GPIO chip arizona, deferring
------------[ cut here ]------------ kobject: 'gpiochip5' (00000000241466f2): is not initialized, yet kobject_get() is being called. WARNING: CPU: 3 PID: 42 at lib/kobject.c:640 kobject_get+0x43/0x70 Call Trace: kobject_get gpio_device_find gpiod_find_and_request gpiod_get snd_byt_wm5102_mc_probe
Not only is the device not initialized yet, but when the gpio-device is added to the list things like the irqchip also have not been initialized yet.
So gpio_device_find() should really ignore the gpio-device until gpiochip_add_data_with_key() is fully done. Add a device_is_registered() check to gpio_device_find() to ignore gpio-devices on the list which are not yet fully initialized.
---
Changes in v2:
-Move device_is_registered() outside of RCU read lock section -Simplify backtrace in commit msg
-Add fixes tag
--- drivers/gpio/gpiolib.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpio/gpiolib.c +3 -0
@@ -1175,6 +1175,9 @@ struct gpio_device *gpio_device_find(const void *data,list_for_each_entry_srcu (gdev, &gpio_devices, list,srcu_read_lock_held (&gpio_devices_srcu)) { +if (!device_is_registered (&gdev->dev)) +continue ; +guard (srcu)(&gdev->srcu); gc =srcu_dereference (gdev->chip, &gdev->srcu);
Signature · 1 line
2.44.0
Quoted 8 lines · Hans de Goede
When a gpiochip gets added by loading a module, then another driver may be waiting for that gpiochip to load on the deferred-probe list.
If the deferred-probe for the consumer of gpiochip then triggers between the
gpiodev_add_to_list_unlocked()calls which makesgpio_device_find()see the chip and thegpiochip_setup_dev()later thengpio_device_find()does akobject_get()on an uninitialzed kobject since the kobject is
uninitialized
Quoted 14 lines
initialized by
gpiochip_setup_dev()callingdevice_initialize():arizona spi-10WM5102:00: cannot find GPIO chip arizona, deferring arizona spi-10WM5102:00: cannot find GPIO chip arizona, deferring
------------[ cut here ]------------ kobject: 'gpiochip5' (00000000241466f2): is not initialized, yet kobject_get() is being called. WARNING: CPU: 3 PID: 42 at lib/kobject.c:640 kobject_get+0x43/0x70 Call Trace: kobject_get gpio_device_find gpiod_find_and_request gpiod_get snd_byt_wm5102_mc_probe
Quoted 8 lines
Not only is the device not initialized yet, but when the gpio-device is added to the list things like the irqchip also have not been initialized yet.
So
gpio_device_find()should really ignore the gpio-device untilgpiochip_add_data_with_key()is fully done. Add adevice_is_registered()check togpio_device_find()to ignore gpio-devices on the list which are not yet fully initialized.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 11 lines · Andy Shevchenko
Quoted 8 lines · Hans de Goede
When a gpiochip gets added by loading a module, then another driver may be waiting for that gpiochip to load on the deferred-probe list.
If the deferred-probe for the consumer of gpiochip then triggers between the
gpiodev_add_to_list_unlocked()calls which makesgpio_device_find()see the chip and thegpiochip_setup_dev()later thengpio_device_find()does akobject_get()on an uninitialzed kobject since the kobject isuninitialized
Bartosz, can you fix this up while merging or do you prefer a v3?
Quoted 18 lines
Quoted 18 lines
initialized by
gpiochip_setup_dev()callingdevice_initialize():arizona spi-10WM5102:00: cannot find GPIO chip arizona, deferring arizona spi-10WM5102:00: cannot find GPIO chip arizona, deferring
------------[ cut here ]------------ kobject: 'gpiochip5' (00000000241466f2): is not initialized, yet kobject_get() is being called. WARNING: CPU: 3 PID: 42 at lib/kobject.c:640 kobject_get+0x43/0x70 Call Trace: kobject_get gpio_device_find gpiod_find_and_request gpiod_get snd_byt_wm5102_mc_probeNot only is the device not initialized yet, but when the gpio-device is added to the list things like the irqchip also have not been initialized yet.
Quoted 6 lines
Quoted 4 lines
So
gpio_device_find()should really ignore the gpio-device untilgpiochip_add_data_with_key()is fully done. Add adevice_is_registered()check togpio_device_find()to ignore gpio-devices on the list which are not yet fully initialized.Reviewed-by Andy Shevchenko <[email protected]>
Thank you for the review.
Regards,
Hans
Quoted 9 lines · Hans de Goede
Hi,
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Hans de Goede
When a gpiochip gets added by loading a module, then another driver may be waiting for that gpiochip to load on the deferred-probe list.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
If the deferred-probe for the consumer of gpiochip then triggers between the
gpiodev_add_to_list_unlocked()calls which makesgpio_device_find()see the chip and thegpiochip_setup_dev()later thengpio_device_find()does akobject_get()on an uninitialzed kobject since the kobject isuninitialized
Bartosz, can you fix this up while merging or do you prefer a v3?
Yes, queued for fixes.
Bart