Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

parisc: led: fix reference leak on failed device registration

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>

authored by

Guangshuo Li and committed by
Helge Deller
707610bc 1221365f

+4 -2
+4 -2
drivers/parisc/led.c
··· 543 543 544 544 static int __init startup_leds(void) 545 545 { 546 - if (platform_device_register(&platform_leds)) 547 - printk(KERN_INFO "LED: failed to register LEDs\n"); 546 + if (platform_device_register(&platform_leds)) { 547 + pr_info("LED: failed to register LEDs\n"); 548 + platform_device_put(&platform_leds); 549 + } 548 550 register_led_regions(); 549 551 return 0; 550 552 }