public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Guangshuo Li <lgs201920130244@gmail.com>
To: Guangshuo Li <lgs201920130244@gmail.com>,
	Paul Mackerras <paulus@ozlabs.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH] macintosh: windfarm_core: fix reference leak on failed device registration
Date: Wed, 15 Apr 2026 22:46:35 +0800	[thread overview]
Message-ID: <20260415144635.3318697-1-lgs201920130244@gmail.com> (raw)

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


                 reply	other threads:[~2026-04-15 14:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260415144635.3318697-1-lgs201920130244@gmail.com \
    --to=lgs201920130244@gmail.com \
    --cc=benh@kernel.crashing.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=paulus@ozlabs.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox