Re: [PATCH] media: vim2m: fix reference leak on failed device registration
From: Guangshuo Li
Date: Thu Apr 16 2026 - 06:19:26 EST
Hi Laurent,
Thanks for the review.
On Thu, 16 Apr 2026 at 17:49, Laurent Pinchart
<laurent.pinchart@xxxxxxxxxxxxxxxx> wrote:
>
> Functions that don't clean after themselves on failure are not a very
> good practice. It indeed seems that platform_device_register() will
> leave a dangling kref. Most callers don't seem to be aware of this
> though, even platform_add_devices() doesn't call platform_device_put() !
> This makes me think that this patch just works around the problem. A
> better solution is needed. Have you investigated if
> platform_device_register() can drop the reference on failure ? What
> problems would that cause ?
>
> > The issue was identified by a static analysis tool I developed and
> > confirmed by manual review.
> >
> > Fixes: 1f923a42033ad ("[media] mem2mem_testdev: rename to vim2m")
>
> Quote unlikely.
>
You are right, this may be a workaround rather than the best fix if the
underlying issue is really in the platform_device_register() failure
semantics.
There is also discussion along the same lines in another patch caused by
the same API pattern:
https://patchew.org/linux/20260415174159.3625777-1-lgs201920130244@xxxxxxxxx/
We are discussing there whether there is a better fix at the API/core
level instead of handling individual callers one by one.
Thanks,
Guangshuo