* [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* Re: [PATCH] eeprom: digsy_mtc: fix reference leak on failed device registration
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
0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2026-04-16 7:52 UTC (permalink / raw)
To: Guangshuo Li
Cc: Arnd Bergmann, Greg Kroah-Hartman, Linus Walleij, linux-kernel, stable
On Thu, Apr 16, 2026 at 12:52:02AM +0800, Guangshuo Li wrote:
> 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.
Thanks for catching this up!
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] eeprom: digsy_mtc: fix reference leak on failed device registration
2026-04-16 7:52 ` Andy Shevchenko
@ 2026-04-24 8:21 ` Guangshuo Li
2026-04-24 8:36 ` Andy Shevchenko
0 siblings, 1 reply; 4+ messages in thread
From: Guangshuo Li @ 2026-04-24 8:21 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Arnd Bergmann, Greg Kroah-Hartman, Linus Walleij, linux-kernel, stable
Hi Andy, all,
Thanks for the review.
Please disregard this patch.
On Thu, 16 Apr 2026 at 15:52, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Thu, Apr 16, 2026 at 12:52:02AM +0800, Guangshuo Li wrote:
> > 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.
>
> Thanks for catching this up!
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
After re-checking it, digsy_mtc_eeprom is a static platform_device and it
does not provide a dev.release callback. Therefore calling
platform_device_put() on the platform_device_register() failure path is
not appropriate here and can trigger the missing release callback warning.
This falls into the same static platform_device pattern pointed out in
the other reviews, so I will drop this patch.
Sorry for the confusion, and thanks again for the review.
Best regards,
Guangshuo Li
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] eeprom: digsy_mtc: fix reference leak on failed device registration
2026-04-24 8:21 ` Guangshuo Li
@ 2026-04-24 8:36 ` Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-04-24 8:36 UTC (permalink / raw)
To: Guangshuo Li
Cc: Arnd Bergmann, Greg Kroah-Hartman, Linus Walleij, linux-kernel, stable
On Fri, Apr 24, 2026 at 04:21:05PM +0800, Guangshuo Li wrote:
> On Thu, 16 Apr 2026 at 15:52, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Thu, Apr 16, 2026 at 12:52:02AM +0800, Guangshuo Li wrote:
...
> After re-checking it, digsy_mtc_eeprom is a static platform_device and it
> does not provide a dev.release callback. Therefore calling
> platform_device_put() on the platform_device_register() failure path is
> not appropriate here and can trigger the missing release callback warning.
>
> This falls into the same static platform_device pattern pointed out in
> the other reviews, so I will drop this patch.
Ah, good point! Indeed, this device is either present for the entire system
run-time or not at all. Even if it's erroneously attempted to be instantiated
it's still not a big deal.
--
With Best Regards,
Andy Shevchenko
^ 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®