Re: [PATCH] soc: microchip: mpfs-sys-controller: fix reference leak on failed device registration
From: Guangshuo Li
Date: Thu Apr 16 2026 - 10:03:40 EST
Hi Conor,
Thanks for the review.
On Thu, 16 Apr 2026 at 21:32, Conor Dooley <conor@xxxxxxxxxx> wrote:
>
> Patch looks reasonable, but not urgent so I will pick it up after -rc1.
> Looking around it doesn't look like this will be a unique patch, so for
> other I would suggest that...
>
> > mpfs_sys_controller_probe()
> > -> platform_device_register(&subdevs[i])
> > -> device_initialize(&subdevs[i].dev)
> > -> setup_pdev_dma_masks(&subdevs[i])
> > -> platform_device_add(&subdevs[i])
>
> ...you redo this section, as it's not clear to me what this actually
> is trying to communicate. AFAIU, what's wrong here is that
> device_initialize() calls kobject_init(), which needs a kobject_put()
> to clean up after it on failure. But this code snippet doesn't tell me
> that, I had to go look for where the reference count was actually
> incremented.
>
I also think your point makes sense. While this patch may look
reasonable at the caller side, the correct fix may not be to handle
individual callers one by one. It may be better to address this in
platform_device_register() itself if the failure semantics there are
the real issue.
We are currently discussing that possibility in another patch of the
same kind, to see whether fixing the API/core code would be a better
approach than patching each caller separately:
https://patchew.org/linux/20260415174159.3625777-1-lgs201920130244@xxxxxxxxx/
Thanks,
Guangshuo