public inbox for linux-parisc@vger.kernel.org
 help / color / mirror / Atom feed
From: Guangshuo Li <lgs201920130244@gmail.com>
To: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	Helge Deller <deller@gmx.de>,
	linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Guangshuo Li <lgs201920130244@gmail.com>, stable@vger.kernel.org
Subject: [PATCH] parisc: led: fix reference leak on failed device registration
Date: Thu, 16 Apr 2026 01:05:15 +0800	[thread overview]
Message-ID: <20260415170515.3605095-1-lgs201920130244@gmail.com> (raw)

When platform_device_register() fails in startup_leds(), the embedded
struct device in platform_leds has already been initialized by
device_initialize(), but the failure path only reports the error and
does not drop the device reference for the current platform device:

  startup_leds()
    -> platform_device_register(&platform_leds)
       -> device_initialize(&platform_leds.dev)
       -> setup_pdev_dma_masks(&platform_leds)
       -> platform_device_add(&platform_leds)

This leads to a reference leak when platform_device_register() fails.
Fix this by calling platform_device_put() after reporting the error.

The issue was identified by a static analysis tool I developed and
confirmed by manual review.

Fixes: 789e527adfc33 ("parisc: led: Rewrite LED/LCD driver to utilizize Linux LED subsystem")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/parisc/led.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c
index 016c9d5a60a8..b299fcc48b08 100644
--- a/drivers/parisc/led.c
+++ b/drivers/parisc/led.c
@@ -543,8 +543,10 @@ static void __init register_led_regions(void)
 
 static int __init startup_leds(void)
 {
-	if (platform_device_register(&platform_leds))
-                printk(KERN_INFO "LED: failed to register LEDs\n");
+	if (platform_device_register(&platform_leds)) {
+		pr_info("LED: failed to register LEDs\n");
+		platform_device_put(&platform_leds);
+	}
 	register_led_regions();
 	return 0;
 }
-- 
2.43.0


             reply	other threads:[~2026-04-15 17:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15 17:05 Guangshuo Li [this message]
2026-04-17  9:39 ` [PATCH] parisc: led: fix reference leak on failed device registration Helge Deller

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=20260415170515.3605095-1-lgs201920130244@gmail.com \
    --to=lgs201920130244@gmail.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=deller@gmx.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-parisc@vger.kernel.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