[PATCH] mfd: cgbc: release the platform device if driver registration fails
From: Wentao Liang
Date: Tue Nov 03 2026 - 04:51:21 EST
cgbc_init() registers the "cgbc" platform device before registering
the platform driver. If platform_driver_register() fails, module
initialisation fails and cgbc_exit() is never called, so the platform
device stays registered and its memory and resources are leaked.
Unregister the platform device before returning the error.
Fixes: 6f1067cfbee7 ("mfd: Add Congatec Board Controller driver")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/mfd/cgbc-core.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/mfd/cgbc-core.c b/drivers/mfd/cgbc-core.c
index 2becaf797646..e9c754c97bdf 100644
--- a/drivers/mfd/cgbc-core.c
+++ b/drivers/mfd/cgbc-core.c
@@ -411,7 +411,11 @@ static int __init cgbc_init(void)
if (IS_ERR(cgbc_pdev))
return PTR_ERR(cgbc_pdev);
- return platform_driver_register(&cgbc_driver);
+ ret = platform_driver_register(&cgbc_driver);
+ if (ret)
+ platform_device_unregister(cgbc_pdev);
+
+ return ret;
}
static void __exit cgbc_exit(void)
--
2.34.1