[PATCH] macintosh: windfarm_core: fix reference leak on failed device registration
From: Guangshuo Li
Date: Wed Apr 15 2026 - 10:46:55 EST
When platform_device_register() fails in windfarm_core_init(), the
embedded struct device in wf_platform_device has already been
initialized by device_initialize(), but the failure path does not drop
the device reference for the current platform device:
windfarm_core_init()
platform_device_register(&wf_platform_device)
device_initialize(&wf_platform_device.dev)
setup_pdev_dma_masks(&wf_platform_device)
return platform_device_add(&wf_platform_device)
This leads to a reference leak when platform_device_register() fails.
Fix this by checking the return value and calling platform_device_put().
The issue was identified by a static analysis tool I developed and
confirmed by manual review.
Fixes: 75722d3992f57 ("[PATCH] ppc64: Thermal control for SMU based machines")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
drivers/macintosh/windfarm_core.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/macintosh/windfarm_core.c b/drivers/macintosh/windfarm_core.c
index 5307b1e34261..4003e72f3a57 100644
--- a/drivers/macintosh/windfarm_core.c
+++ b/drivers/macintosh/windfarm_core.c
@@ -436,9 +436,14 @@ EXPORT_SYMBOL_GPL(wf_clear_overtemp);
static int __init windfarm_core_init(void)
{
+ int err;
+
DBG("wf: core loaded\n");
- platform_device_register(&wf_platform_device);
+ err = platform_device_register(&wf_platform_device);
+ if (err)
+ platform_device_put(&wf_platform_device);
+
return 0;
}
--
2.43.0