blob: 76a77736a8e0036279bc6f7180bc845533935bc5 [file]
From 707610bcccbd0327530938e33f3f33211a640a4e Mon Sep 17 00:00:00 2001
From: Guangshuo Li <lgs201920130244@gmail.com>
Date: Thu, 16 Apr 2026 01:05:15 +0800
Subject: parisc: led: fix reference leak on failed device registration
From: Guangshuo Li <lgs201920130244@gmail.com>
commit 707610bcccbd0327530938e33f3f33211a640a4e upstream.
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>
Signed-off-by: Helge Deller <deller@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/parisc/led.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
--- a/drivers/parisc/led.c
+++ b/drivers/parisc/led.c
@@ -547,8 +547,10 @@ static void __init register_led_regions(
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;
}