Re: [PATCH 3/5] mtd: maps: physmap: fix reference leak on failed device registration
From: Miquel Raynal
Date: Mon May 04 2026 - 10:05:37 EST
On 04/05/2026 at 13:08:45 +03, Vastargazing <vebohr@xxxxxxxxx> wrote:
> When platform_device_register() fails in physmap_init(), the embedded
> struct device has already been initialized by device_initialize() inside
> platform_device_register(). The error path unregisters the driver but
> returns without dropping the device reference:
>
> physmap_init()
> -> platform_device_register(&physmap_flash)
> -> device_initialize(&physmap_flash.dev) /* kref = 1 */
> -> platform_device_add(&physmap_flash) /* fails */
> <- platform_driver_unregister() called, but kref still 1
>
> Per platform_device_register() kernel-doc:
>
> NOTE: _Never_ directly free @pdev after calling this function, even if
> it returned an error! Always use platform_device_put() to give up the
> reference initialised in this function instead.
>
> Fix this by calling platform_device_put() before unregistering the driver.
>
> Fixes: 73566edf9b91 ("[MTD] Convert physmap to platform driver")
> Cc: stable@xxxxxxxxxxxxxxx
> Assisted-by: GitHub Copilot (Claude Sonnet 4.5)
> Signed-off-by: Vastargazing <vebohr@xxxxxxxxx>
Somehow b4 applied another patch from that series, I'm not sure why. I
just dropped it. Please resend this patch alone.
Also, your SoB line seems to be incorrect, we need a proper name, please
have a loot at the DCO.
Thanks,
Miquèl