public inbox for linuxppc-dev@ozlabs.org
 help / color / mirror / Atom feed
From: Guangshuo Li <lgs201920130244@gmail.com>
To: Guangshuo Li <lgs201920130244@gmail.com>,
	Kees Cook <kees@kernel.org>,
	Johannes Berg <johannes@sipsolutions.net>,
	Paul Mackerras <paulus@ozlabs.org>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH] macintosh: adb: fix reference leak on failed platform device registration
Date: Wed, 15 Apr 2026 22:37:01 +0800	[thread overview]
Message-ID: <20260415143701.3309681-1-lgs201920130244@gmail.com> (raw)

When platform_device_register() fails in adbdev_init(), the embedded
struct device in adb_pfdev has already been initialized by
device_initialize(), but the failure path does not drop the device
reference for the current platform device:

  adbdev_init()
    platform_device_register(&adb_pfdev)
      device_initialize(&adb_pfdev.dev)
      setup_pdev_dma_masks(&adb_pfdev)
      return platform_device_add(&adb_pfdev)

As documented in platform_device_register(), the caller must use
platform_device_put() to give up the reference initialized in this
function when registration fails.

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: c9f6d3d5c6d4f ("[POWERPC] adb: Replace sleep notifier with platform driver suspend/resume hooks")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/macintosh/adb.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index fe150125e099..eff06f78aa80 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -883,6 +883,8 @@ adb_dummy_probe(struct platform_device *dev)
 static void __init
 adbdev_init(void)
 {
+	int err;
+
 	if (register_chrdev(ADB_MAJOR, "adb", &adb_fops)) {
 		pr_err("adb: unable to get major %d\n", ADB_MAJOR);
 		return;
@@ -893,6 +895,9 @@ adbdev_init(void)
 
 	device_create(&adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), NULL, "adb");
 
-	platform_device_register(&adb_pfdev);
+	err = platform_device_register(&adb_pfdev);
+	if (err)
+		platform_device_put(&adb_pfdev);
+
 	platform_driver_probe(&adb_pfdrv, adb_dummy_probe);
 }
-- 
2.43.0



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

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15 14:37 Guangshuo Li [this message]
2026-04-24  8:11 ` [PATCH] macintosh: adb: fix reference leak on failed platform device registration Guangshuo Li

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=20260415143701.3309681-1-lgs201920130244@gmail.com \
    --to=lgs201920130244@gmail.com \
    --cc=johannes@sipsolutions.net \
    --cc=kees@kernel.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