public inbox for driver-core@lists.linux.dev
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Jiri Slaby <jirislaby@kernel.org>
Cc: Takashi Iwai <tiwai@suse.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	Guangshuo Li <lgs201920130244@gmail.com>,
	linux-kernel@vger.kernel.org, driver-core@lists.linux.dev
Subject: Re: [PATCH] ALSA: pcmtest: fix reference leak on failed device registration
Date: Thu, 23 Apr 2026 09:39:36 +0200	[thread overview]
Message-ID: <875x5i3z2f.wl-tiwai@suse.de> (raw)
In-Reply-To: <d25b3ecd-9941-4b3b-9480-4f8f16a8ecd7@kernel.org>

On Thu, 23 Apr 2026 07:19:20 +0200,
Jiri Slaby wrote:
> 
> On 17. 04. 26, 12:52, Takashi Iwai wrote:
> > On Fri, 17 Apr 2026 09:57:20 +0200,
> > Takashi Iwai wrote:
> >> 
> >> On Wed, 15 Apr 2026 21:31:38 +0200,
> >> Guangshuo Li wrote:
> >>> 
> >>> When platform_device_register() fails in mod_init(), the embedded struct
> >>> device in pcmtst_pdev has already been initialized by
> >>> device_initialize(), but the failure path returns the error without
> >>> dropping the device reference for the current platform device:
> >>> 
> >>>    mod_init()
> >>>      -> platform_device_register(&pcmtst_pdev)
> >>>         -> device_initialize(&pcmtst_pdev.dev)
> >>>         -> setup_pdev_dma_masks(&pcmtst_pdev)
> >>>         -> platform_device_add(&pcmtst_pdev)
> >>> 
> >>> This leads to a reference leak when platform_device_register() fails.
> >>> Fix this by calling platform_device_put() before returning the error.
> >>> 
> >>> The issue was identified by a static analysis tool I developed and
> >>> confirmed by manual review.
> >>> 
> >>> Fixes: 315a3d57c64c5 ("ALSA: Implement the new Virtual PCM Test Driver")
> >>> Cc: stable@vger.kernel.org
> >>> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> >> 
> >> Thanks, applied now.
> > 
> > ... 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.
> 
> Moreover, unless the static pcmtst_pdev has ->type->release or
> ->release set, the patch triggers a warning upon put().

Ah a good point, the call should be conditional.

> > 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.
> 
> Yes, that's what should be done instead.

OK, I'm going to revert this patch for pcmtest.c for now (so back to
the upstream state again), so that we can work on the
platform_device_register() side.


thanks,

Takashi

      reply	other threads:[~2026-04-23  7:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260415193138.3861297-1-lgs201920130244@gmail.com>
     [not found] ` <87h5padnof.wl-tiwai@suse.de>
2026-04-17 10:52   ` [PATCH] ALSA: pcmtest: fix reference leak on failed device registration Takashi Iwai
2026-04-17 11:30     ` Guangshuo Li
2026-04-23  5:19     ` Jiri Slaby
2026-04-23  7:39       ` Takashi Iwai [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875x5i3z2f.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=lgs201920130244@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox