[PATCH] ieee802154: fakelb: release platform device if driver registration fails
From: Wentao Liang
Date: Tue Nov 03 2026 - 06:09:27 EST
fakelb_init_module() registers a platform device and then registers the
platform driver, returning the result of the latter directly. If driver
registration fails, module initialization fails and the module exit
function is never run, so the platform device is never unregistered and
leaks.
Check the result of platform_driver_register() and unregister the device
on failure. Also check the device registration result, which can be an
ERR_PTR, before using the stored pointer.
Fixes: e1e49b641387 ("drivers/ieee802154: IEEE 802.15.4 loopback driver")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/net/ieee802154/fakelb.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ieee802154/fakelb.c b/drivers/net/ieee802154/fakelb.c
index e11d8eda85ea..35863c3aff44 100644
--- a/drivers/net/ieee802154/fakelb.c
+++ b/drivers/net/ieee802154/fakelb.c
@@ -243,12 +243,20 @@ static struct platform_driver ieee802154fake_driver = {
static __init int fakelb_init_module(void)
{
+ int rc;
+
ieee802154fake_dev = platform_device_register_simple(
"ieee802154fakelb", -1, NULL, 0);
+ if (IS_ERR(ieee802154fake_dev))
+ return PTR_ERR(ieee802154fake_dev);
pr_warn("fakelb driver is marked as deprecated, please use mac802154_hwsim!\n");
- return platform_driver_register(&ieee802154fake_driver);
+ rc = platform_driver_register(&ieee802154fake_driver);
+ if (rc)
+ platform_device_unregister(ieee802154fake_dev);
+
+ return rc;
}
static __exit void fake_remove_module(void)
--
2.34.1