Re: [PATCH] ALSA: pcmtest: fix reference leak on failed device registration

Guangshuo Li
2026-04-17T11:30:20Z

Hi Takashi,

Thanks for reviewing.

On Fri, 17 Apr 2026 at 18:52, Takashi Iwai <tiwai@suse.de> wrote:
>
>
> ... and now I looked through the whole tree, and noticed that the
> majority of callers of platform_device_register() don't care the error
> cases without calling platform_device_put(). There are over a hundred
> callers of platform_device_register() while only 5 or so are doing the
> proper cleanup at the error.
>
> Judging from the numbers above, it might be better to change the
> behavior of platform_device_register() itself to call *_put() at the
> error case internally. Or, if we keep the current behavior, at least
> we should properly document it.
>
> Greg, Rafael, Danilo, what do you think?
>
>
> thanks,
>
> Takashi

I agree with your observation. Given that many callers of
platform_device_register() do not handle the error path with a
matching platform_device_put(), this does seem more like an issue
related to the core/API behavior, or at least something that should be
documented more clearly.

Also, the underlying issue here appears to be related to the
platform_device_register() core/API behavior. We are currently
discussing in another similar case whether the better fix, if any,
should be made in the core/API code rather than in individual callers:

https://patchew.org/linux/20260415174159.3625777-1-lgs201920130244@gmail.com/

Once that discussion reaches a conclusion, we will revisit this and
make the appropriate fix if needed.

Thanks,
Guangshuo