public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] macintosh: windfarm_core: fix reference leak on failed device registration
@ 2026-04-15 14:46 Guangshuo Li
  0 siblings, 0 replies; only message in thread
From: Guangshuo Li @ 2026-04-15 14:46 UTC (permalink / raw)
  To: Guangshuo Li, Paul Mackerras, Benjamin Herrenschmidt,
	linuxppc-dev, linux-kernel
  Cc: stable

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@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-04-15 14:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-15 14:46 [PATCH] macintosh: windfarm_core: fix reference leak on failed device registration Guangshuo Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox