[PATCH] eeprom: digsy_mtc: fix reference leak on failed device registration

From: Guangshuo Li

Date: Wed Apr 15 2026 - 13:16:53 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
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