* [PATCH] mfd: sm501: Fix error handling in sm501_base_init()
@ 2022-12-08 13:04 Yuan Can
0 siblings, 0 replies; only message in thread
From: Yuan Can @ 2022-12-08 13:04 UTC (permalink / raw)
To: lee, akpm, sameo, adobriyan, linux-kernel; +Cc: yuancan
A problem about modprobe sm501 failed is triggered with the following log
given:
[ 4919.196338] Error: Driver 'sm501' is already registered, aborting...
insmod: ERROR: could not insert module sm501.ko: Device or resource busy
The reason is that sm501_base_init() returns pci_register_driver()
directly without checking its return value, if pci_register_driver()
failed, it returns without unregistering sm501_plat_driver, resulting
the sm501 can never be installed later.
A simple call graph is shown as below:
sm501_base_init()
platform_driver_register() # sm501_plat_driver are registered
pci_register_driver()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened
# return without unregister sm501_plat_driver
Fix by calling platform_driver_unregister() when pci_register_driver()
returns error.
Fixes: 158abca5f699 ("mfd: fix sm501 section mismatches")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
drivers/mfd/sm501.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index 3ac4508a6742..c1efa040e94e 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -1726,7 +1726,13 @@ static int __init sm501_base_init(void)
if (ret < 0)
return ret;
- return pci_register_driver(&sm501_pci_driver);
+ ret = pci_register_driver(&sm501_pci_driver);
+ if (ret) {
+ platform_driver_unregister(&sm501_plat_driver);
+ return ret;
+ }
+
+ return 0;
}
static void __exit sm501_base_exit(void)
--
2.17.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-12-08 13:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-08 13:04 [PATCH] mfd: sm501: Fix error handling in sm501_base_init() Yuan Can
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).