mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] eeprom: digsy_mtc: fix reference leak on failed device registration
@ 2026-04-15 16:52 Guangshuo Li
  2026-04-16  7:52 ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Guangshuo Li @ 2026-04-15 16:52 UTC (permalink / raw)
  To: Arnd Bergmann, Greg Kroah-Hartman, Guangshuo Li, Andy Shevchenko,
	Linus Walleij, linux-kernel
  Cc: stable

When platform_device_register() fails in digsy_mtc_eeprom_devices_init(),
the embedded struct device in digsy_mtc_eeprom has already been
initialized by device_initialize(), but the failure path only removes
the software node and does not drop the device reference for the current
platform device:

  digsy_mtc_eeprom_devices_init()
    -> platform_device_register(&digsy_mtc_eeprom)
       -> device_initialize(&digsy_mtc_eeprom.dev)
       -> setup_pdev_dma_masks(&digsy_mtc_eeprom)
       -> platform_device_add(&digsy_mtc_eeprom)

This leads to a reference leak when platform_device_register() fails.
Fix this by calling platform_device_put() after removing the software
node.

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

Fixes: c8ed97d8c3984 ("eeprom: digsy_mtc: Convert to use GPIO descriptors")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/misc/eeprom/digsy_mtc_eeprom.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/eeprom/digsy_mtc_eeprom.c b/drivers/misc/eeprom/digsy_mtc_eeprom.c
index ee58f7ce5bfa..54fcbdc0412a 100644
--- a/drivers/misc/eeprom/digsy_mtc_eeprom.c
+++ b/drivers/misc/eeprom/digsy_mtc_eeprom.c
@@ -89,8 +89,10 @@ static int __init digsy_mtc_eeprom_devices_init(void)
 		return ret;
 
 	ret = platform_device_register(&digsy_mtc_eeprom);
-	if (ret)
+	if (ret) {
 		device_remove_software_node(&digsy_mtc_eeprom.dev);
+		platform_device_put(&digsy_mtc_eeprom);
+	}
 
 	return ret;
 }
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-04-24  8:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-15 16:52 [PATCH] eeprom: digsy_mtc: fix reference leak on failed device registration Guangshuo Li
2026-04-16  7:52 ` Andy Shevchenko
2026-04-24  8:21   ` Guangshuo Li
2026-04-24  8:36     ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®