All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Dmitry Nikiforov <Dm1tryNk@yandex.ru>
Cc: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil@xs4all.nl>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	lvc-project@linuxtesting.org
Subject: Re: [PATCH v2] media: davinci: vpif: Fix memory leaks in probe error path
Date: Wed, 16 Apr 2025 08:11:54 +0200	[thread overview]
Message-ID: <Z_9KKrbKFDekGLOw@hovoldconsulting.com> (raw)
In-Reply-To: <20250415223825.3777-1-Dm1tryNk@yandex.ru>

On Wed, Apr 16, 2025 at 01:38:20AM +0300, Dmitry Nikiforov wrote:
> If `of_graph_get_endpoint_by_regs()` fails, the probe function currently
> returns 0, skipping cleanup. 
> 
> Also, if an error occurs during the initialization of `pdev_display`,
> the allocated platform device `pdev_capture` is not released properly,
> leading to a memory leak.
> 
> Adjust error path handling to fix the leaks.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 43acb728bbc4 ("media: davinci: vpif: fix use-after-free on driver unbind")
> Signed-off-by: Dmitry Nikiforov <Dm1tryNk@yandex.ru>
> ---
> v2: also fix of_graph_get_endpoint_by_regs() error path (Johan Hovold).
>  drivers/media/platform/ti/davinci/vpif.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/ti/davinci/vpif.c b/drivers/media/platform/ti/davinci/vpif.c
> index a81719702a22..4839e34e5d29 100644
> --- a/drivers/media/platform/ti/davinci/vpif.c
> +++ b/drivers/media/platform/ti/davinci/vpif.c
> @@ -467,7 +467,8 @@ static int vpif_probe(struct platform_device *pdev)
>  	 */
>  	endpoint = of_graph_get_endpoint_by_regs(pdev->dev.of_node, 0, -1);
>  	if (!endpoint)
> -		return 0;
> +		ret = -ENODEV;
> +		goto err_put_rpm;

This looks wrong, since you're changing an early success path into a
probe failure.

Either way, that would need to go into a separate patch.

I was referring to the error handling for the pdev_display allocation
earlier, which also needs to deregister the capture device on errors
(and that can be done as part of this patch).

>  	of_node_put(endpoint);
>  
>  	/*
> @@ -527,6 +528,7 @@ static int vpif_probe(struct platform_device *pdev)
>  
>  err_put_pdev_display:
>  	platform_device_put(pdev_display);
> +	platform_device_del(pdev_capture);
>  err_put_pdev_capture:
>  	platform_device_put(pdev_capture);
>  err_put_rpm:

Johan

      reply	other threads:[~2025-04-16  6:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-15 22:38 [PATCH v2] media: davinci: vpif: Fix memory leaks in probe error path Dmitry Nikiforov
2025-04-16  6:11 ` Johan Hovold [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=Z_9KKrbKFDekGLOw@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=Dm1tryNk@yandex.ru \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=mchehab@kernel.org \
    --cc=prabhakar.csengg@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.