From: Shuah Khan <skhan@linuxfoundation.org>
To: Guangshuo Li <lgs201920130244@gmail.com>,
Kieran Bingham <kieran.bingham@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil@kernel.org>,
Dafna Hirschfeld <dafna.hirschfeld@collabora.com>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org, Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] media: vimc: fix reference leak on failed device registration
Date: Wed, 15 Apr 2026 10:01:51 -0600 [thread overview]
Message-ID: <75275f6e-8314-4dd6-a54e-95320c2224e2@linuxfoundation.org> (raw)
In-Reply-To: <20260415154537.3451732-1-lgs201920130244@gmail.com>
On 4/15/26 09:45, Guangshuo Li wrote:
> When platform_device_register() fails in vimc_init(), the embedded
> struct device in vimc_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:
>
> vimc_init()
> -> platform_device_register(&vimc_pdev)
> -> device_initialize(&vimc_pdev.dev)
> -> setup_pdev_dma_masks(&vimc_pdev)
> -> platform_device_add(&vimc_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.
Can you share your manual review?
Can other static analysis tools for example scripts/coccinelle support
your findings?
>
> Fixes: 4babf057c143f ("media: vimc: allocate vimc_device dynamically")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
> drivers/media/test-drivers/vimc/vimc-core.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/media/test-drivers/vimc/vimc-core.c b/drivers/media/test-drivers/vimc/vimc-core.c
> index 15167e127461..fee0c7a09c4f 100644
> --- a/drivers/media/test-drivers/vimc/vimc-core.c
> +++ b/drivers/media/test-drivers/vimc/vimc-core.c
> @@ -421,6 +421,7 @@ static int __init vimc_init(void)
> if (ret) {
> dev_err(&vimc_pdev.dev,
> "platform device registration failed (err=%d)\n", ret);
> + platform_device_put(&vimc_pdev);
Where does platform_device_get() happen when platform_device_register() fails?
thanks,
-- Shuah
next prev parent reply other threads:[~2026-04-15 16:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 15:45 [PATCH] media: vimc: fix reference leak on failed device registration Guangshuo Li
2026-04-15 16:01 ` Shuah Khan [this message]
2026-04-15 16:56 ` Guangshuo Li
2026-04-15 20:49 ` Shuah Khan
2026-04-16 9:11 ` Guangshuo Li
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=75275f6e-8314-4dd6-a54e-95320c2224e2@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=dafna.hirschfeld@collabora.com \
--cc=hverkuil@kernel.org \
--cc=kieran.bingham@ideasonboard.com \
--cc=lgs201920130244@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=stable@vger.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