LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: Young Xiao <92siuyang@gmail.com>,
prabhakar.csengg@gmail.com, mchehab@kernel.org,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] media: davinci: vpif_capture: fix memory leak in vpif_probe()
Date: Mon, 3 Jun 2019 13:55:00 +0200 [thread overview]
Message-ID: <9a2b8351-cdb7-cec7-87d0-7aafb93ab647@xs4all.nl> (raw)
In-Reply-To: <1559135399-28998-1-git-send-email-92siuyang@gmail.com>
On 5/29/19 3:09 PM, Young Xiao wrote:
> If vpif_probe() fails on vpif_probe_complete(), then memory
> allocated at initialize_vpif() for global vpif_obj.dev[i]
> become unreleased.
>
> The patch adds deallocation of vpif_obj.dev[i] on the error path.
>
> Signed-off-by: Young Xiao <92siuyang@gmail.com>
> ---
> drivers/media/platform/davinci/vpif_capture.c | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
> index b5aacb0..63e6ec4 100644
> --- a/drivers/media/platform/davinci/vpif_capture.c
> +++ b/drivers/media/platform/davinci/vpif_capture.c
> @@ -1621,6 +1621,14 @@ vpif_capture_get_pdata(struct platform_device *pdev)
> return NULL;
> }
>
> +static void free_vpif_objs(void)
> +{
> + int i;
> +
> + for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++)
> + kfree(vpif_obj.dev[i]);
> +}
> +
> /**
> * vpif_probe : This function probes the vpif capture driver
> * @pdev: platform device pointer
> @@ -1701,7 +1709,10 @@ static __init int vpif_probe(struct platform_device *pdev)
> "registered sub device %s\n",
> subdevdata->name);
> }
> - vpif_probe_complete();
> + err = vpif_probe_complete();
> + if (err) {
> + goto probe_subdev_out;
> + }
No need for { and } as per kernel coding style.
> } else {
> vpif_obj.notifier.ops = &vpif_async_ops;
> err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev,
> @@ -1722,6 +1733,7 @@ static __init int vpif_probe(struct platform_device *pdev)
> v4l2_device_unregister(&vpif_obj.v4l2_dev);
> cleanup:
> v4l2_async_notifier_cleanup(&vpif_obj.notifier);
> + free_vpif_objs();
This would break the case where initialize_vpif() returns an error, since
initialize_vpif already frees these objects on error.
In this case the easiest way of doing this is to just return if initialize_vpif
returns an error. No need to clean up anything.
Regards,
Hans
>
> return err;
> }
> @@ -1748,8 +1760,8 @@ static int vpif_remove(struct platform_device *device)
> ch = vpif_obj.dev[i];
> /* Unregister video device */
> video_unregister_device(&ch->video_dev);
> - kfree(vpif_obj.dev[i]);
> }
> + free_vpif_objs()
> return 0;
> }
>
>
next prev parent reply other threads:[~2019-06-03 11:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-29 13:09 Young Xiao
2019-06-03 11:55 ` Hans Verkuil [this message]
2019-06-04 7:15 ` Yang Xiao
2019-06-04 7:50 Young Xiao
2019-06-04 8:15 ` Lad, Prabhakar
2019-06-04 8:33 ` Yang Xiao
2019-06-04 8:47 ` Lad, Prabhakar
2019-06-04 12:26 Young Xiao
2019-06-05 20:20 ` Lad, Prabhakar
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=9a2b8351-cdb7-cec7-87d0-7aafb93ab647@xs4all.nl \
--to=hverkuil@xs4all.nl \
--cc=92siuyang@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=prabhakar.csengg@gmail.com \
--subject='Re: [PATCH] media: davinci: vpif_capture: fix memory leak in vpif_probe()' \
/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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).