public inbox for linux-fbdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Helge Deller <deller@gmx.de>
To: Guangshuo Li <lgs201920130244@gmail.com>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Kees Cook <kees@kernel.org>,
	Dan Carpenter <dan.carpenter@linaro.org>,
	Tomi Valkeinen <tomi.valkeinen@nokia.com>,
	linux-fbdev@vger.kernel.org, linux-omap@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fbdev: omapfb: fix reference leak on failed device registration
Date: Wed, 22 Apr 2026 16:30:54 +0200	[thread overview]
Message-ID: <0bd64a89-6530-4447-8a36-01f8803728f0@gmx.de> (raw)
In-Reply-To: <20260415191747.3845525-1-lgs201920130244@gmail.com>

Hello Guanghshuo,

On 4/15/26 21:17, Guangshuo Li wrote:
> When platform_device_register() fails in omapfb_probe(), the embedded
> struct device in omapdss_device has already been initialized by
> device_initialize(), but the failure path only reports the error and
> returns without dropping the device reference for the current platform
> device:
> 
>    omapfb_probe()
>      -> platform_device_register(&omapdss_device)
>         -> device_initialize(&omapdss_device.dev)
>         -> setup_pdev_dma_masks(&omapdss_device)
>         -> platform_device_add(&omapdss_device)
> 
> This leads to a reference leak when platform_device_register() fails.
> Fix this by calling platform_device_put() before returning the error.

I see you submitted quite some patches, all about the same issue.
I did not yet fully checked if there is really a reference leak, but even if
it would be, I think it's wrong that all the callers in the whole Linux kernel source
would now need to use platform_device_put(). To me it then seems as if everyone got it wrong.
IMHO if platform_device_register() fails it should put the device itself before
returning.
Just looking at generic code, see platform_add_devices() in drivers/base/platform.c
which seem to have it wrong too then...

Helge


> The issue was identified by a static analysis tool I developed and
> confirmed by manual review.
> 
> Fixes: f778a12dd3320 ("OMAP: OMAPFB: fix clk_get for RFBI")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
>   drivers/video/fbdev/omap/omapfb_main.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/video/fbdev/omap/omapfb_main.c b/drivers/video/fbdev/omap/omapfb_main.c
> index cafe859d6e5a..0d47a8aec5c5 100644
> --- a/drivers/video/fbdev/omap/omapfb_main.c
> +++ b/drivers/video/fbdev/omap/omapfb_main.c
> @@ -1768,6 +1768,7 @@ static int omapfb_probe(struct platform_device *pdev)
>   	r = platform_device_register(&omapdss_device);
>   	if (r) {
>   		dev_err(&pdev->dev, "can't register omapdss device\n");
> +		platform_device_put(&omapdss_device);
>   		return r;
>   	}
>   


      reply	other threads:[~2026-04-22 14:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15 19:17 [PATCH] fbdev: omapfb: fix reference leak on failed device registration Guangshuo Li
2026-04-22 14:30 ` Helge Deller [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=0bd64a89-6530-4447-8a36-01f8803728f0@gmx.de \
    --to=deller@gmx.de \
    --cc=dan.carpenter@linaro.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kees@kernel.org \
    --cc=lgs201920130244@gmail.com \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=tomi.valkeinen@nokia.com \
    --cc=tzimmermann@suse.de \
    /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