Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: omap: do not register driver in probe()

Commit 11a78b794496 ("ARM: OMAP: MPUIO wake updates") registers the
omap_mpuio_driver from omap_mpuio_init(), which is called from
omap_gpio_probe().

However, it neither makes sense to register drivers from probe()
callbacks of other drivers, nor does the driver core allow registering
drivers with a device lock already being held.

The latter was revealed by commit dc23806a7c47 ("driver core: enforce
device_lock for driver_match_device()") leading to a potential deadlock
condition described in [1].

Additionally, the omap_mpuio_driver is never unregistered from the
driver core, even if the module is unloaded.

Hence, register the omap_mpuio_driver from the module initcall and
unregister it in module_exit().

Link: https://lore.kernel.org/lkml/DFU7CEPUSG9A.1KKGVW4HIPMSH@kernel.org/ [1]
Fixes: dc23806a7c47 ("driver core: enforce device_lock for driver_match_device()")
Fixes: 11a78b794496 ("ARM: OMAP: MPUIO wake updates")
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Link: https://patch.msgid.link/20260127201725.35883-1-dakr@kernel.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

authored by

Danilo Krummrich and committed by
Bartosz Golaszewski
730e5ebf d02f20a4

+18 -4
+18 -4
drivers/gpio/gpio-omap.c
··· 799 799 800 800 static inline void omap_mpuio_init(struct gpio_bank *bank) 801 801 { 802 - platform_set_drvdata(&omap_mpuio_device, bank); 802 + static bool registered; 803 803 804 - if (platform_driver_register(&omap_mpuio_driver) == 0) 805 - (void) platform_device_register(&omap_mpuio_device); 804 + platform_set_drvdata(&omap_mpuio_device, bank); 805 + if (!registered) { 806 + (void)platform_device_register(&omap_mpuio_device); 807 + registered = true; 808 + } 806 809 } 807 810 808 811 /*---------------------------------------------------------------------*/ ··· 1578 1575 */ 1579 1576 static int __init omap_gpio_drv_reg(void) 1580 1577 { 1581 - return platform_driver_register(&omap_gpio_driver); 1578 + int ret; 1579 + 1580 + ret = platform_driver_register(&omap_mpuio_driver); 1581 + if (ret) 1582 + return ret; 1583 + 1584 + ret = platform_driver_register(&omap_gpio_driver); 1585 + if (ret) 1586 + platform_driver_unregister(&omap_mpuio_driver); 1587 + 1588 + return ret; 1582 1589 } 1583 1590 postcore_initcall(omap_gpio_drv_reg); 1584 1591 1585 1592 static void __exit omap_gpio_exit(void) 1586 1593 { 1587 1594 platform_driver_unregister(&omap_gpio_driver); 1595 + platform_driver_unregister(&omap_mpuio_driver); 1588 1596 } 1589 1597 module_exit(omap_gpio_exit); 1590 1598