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

From: Andy Shevchenko

Date: Thu Apr 16 2026 - 03:52:42 EST


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@xxxxxxxxxxxxxxx>

--
With Best Regards,
Andy Shevchenko