linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: s5p-g2d: Fix a memory leak in an error handling path in 'g2d_probe()'
@ 2020-04-26 20:06 Christophe JAILLET
  2020-06-24 14:46 ` Hans Verkuil
  2020-06-25 20:19 ` Christophe JAILLET
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2020-04-26 20:06 UTC (permalink / raw)
  To: kyungmin.park, kamil, a.hajda, mchehab, s.nawrocki, sachin.kamat
  Cc: linux-arm-kernel, linux-media, linux-kernel, kernel-janitors,
	Christophe JAILLET

Memory allocated with 'v4l2_m2m_init()' must be freed by a corresponding
call to 'v4l2_m2m_release()'

Fixes: 5ce60d790a24 ("[media] s5p-g2d: Add DT based discovery support")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/media/platform/s5p-g2d/g2d.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
index 6932fd47071b..ded6fa24677c 100644
--- a/drivers/media/platform/s5p-g2d/g2d.c
+++ b/drivers/media/platform/s5p-g2d/g2d.c
@@ -717,12 +717,14 @@ static int g2d_probe(struct platform_device *pdev)
 	of_id = of_match_node(exynos_g2d_match, pdev->dev.of_node);
 	if (!of_id) {
 		ret = -ENODEV;
-		goto unreg_video_dev;
+		goto free_m2m;
 	}
 	dev->variant = (struct g2d_variant *)of_id->data;
 
 	return 0;
 
+free_m2m:
+	v4l2_m2m_release(dev->m2m_dev);
 unreg_video_dev:
 	video_unregister_device(dev->vfd);
 rel_vdev:
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] media: s5p-g2d: Fix a memory leak in an error handling path in 'g2d_probe()'
  2020-04-26 20:06 [PATCH] media: s5p-g2d: Fix a memory leak in an error handling path in 'g2d_probe()' Christophe JAILLET
@ 2020-06-24 14:46 ` Hans Verkuil
  2020-06-25 20:19 ` Christophe JAILLET
  1 sibling, 0 replies; 3+ messages in thread
From: Hans Verkuil @ 2020-06-24 14:46 UTC (permalink / raw)
  To: Christophe JAILLET, kyungmin.park, kamil, a.hajda, mchehab,
	s.nawrocki, sachin.kamat
  Cc: linux-arm-kernel, linux-media, linux-kernel, kernel-janitors

On 26/04/2020 22:06, Christophe JAILLET wrote:
> Memory allocated with 'v4l2_m2m_init()' must be freed by a corresponding
> call to 'v4l2_m2m_release()'
> 
> Fixes: 5ce60d790a24 ("[media] s5p-g2d: Add DT based discovery support")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/media/platform/s5p-g2d/g2d.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
> index 6932fd47071b..ded6fa24677c 100644
> --- a/drivers/media/platform/s5p-g2d/g2d.c
> +++ b/drivers/media/platform/s5p-g2d/g2d.c
> @@ -717,12 +717,14 @@ static int g2d_probe(struct platform_device *pdev)
>  	of_id = of_match_node(exynos_g2d_match, pdev->dev.of_node);
>  	if (!of_id) {
>  		ret = -ENODEV;
> -		goto unreg_video_dev;
> +		goto free_m2m;
>  	}
>  	dev->variant = (struct g2d_variant *)of_id->data;
>  
>  	return 0;
>  
> +free_m2m:
> +	v4l2_m2m_release(dev->m2m_dev);
>  unreg_video_dev:
>  	video_unregister_device(dev->vfd);
>  rel_vdev:
> 

This isn't right. The real problem here is that video_register_device() is
called before several other initialisations as done, such as v4l2_m2m_init and
the of_match_node check.

To do this properly video_register_device() should be called last in the probe()
function.

Regards,

	Hans

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] media: s5p-g2d: Fix a memory leak in an error handling path in 'g2d_probe()'
  2020-04-26 20:06 [PATCH] media: s5p-g2d: Fix a memory leak in an error handling path in 'g2d_probe()' Christophe JAILLET
  2020-06-24 14:46 ` Hans Verkuil
@ 2020-06-25 20:19 ` Christophe JAILLET
  1 sibling, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2020-06-25 20:19 UTC (permalink / raw)
  To: hverkuil, kyungmin.park, kamil, a.hajda, mchehab
  Cc: linux-arm-kernel, linux-media, linux-kernel, kernel-janitors,
	Christophe JAILLET

Memory allocated with 'v4l2_m2m_init()' must be freed by a corresponding
call to 'v4l2_m2m_release()'

Also reorder the code at the end of the probe function so that
'video_register_device()' is called last.
Update the error handling path accordingly.

Fixes: 5ce60d790a24 ("[media] s5p-g2d: Add DT based discovery support")
Fixes: 918847341af0 ("[media] v4l: add G2D driver for s5p device family")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
V2: Call 'video_register_device()' as required by Hans Verkuil <hverkuil@xs4all.nl>

Compile tested only.
---
 drivers/media/platform/s5p-g2d/g2d.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
index 6932fd47071b..fb2e48dbabd4 100644
--- a/drivers/media/platform/s5p-g2d/g2d.c
+++ b/drivers/media/platform/s5p-g2d/g2d.c
@@ -695,21 +695,13 @@ static int g2d_probe(struct platform_device *pdev)
 	vfd->lock = &dev->mutex;
 	vfd->v4l2_dev = &dev->v4l2_dev;
 	vfd->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING;
-	ret = video_register_device(vfd, VFL_TYPE_VIDEO, 0);
-	if (ret) {
-		v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
-		goto rel_vdev;
-	}
-	video_set_drvdata(vfd, dev);
-	dev->vfd = vfd;
-	v4l2_info(&dev->v4l2_dev, "device registered as /dev/video%d\n",
-								vfd->num);
+
 	platform_set_drvdata(pdev, dev);
 	dev->m2m_dev = v4l2_m2m_init(&g2d_m2m_ops);
 	if (IS_ERR(dev->m2m_dev)) {
 		v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem device\n");
 		ret = PTR_ERR(dev->m2m_dev);
-		goto unreg_video_dev;
+		goto rel_vdev;
 	}
 
 	def_frame.stride = (def_frame.width * def_frame.fmt->depth) >> 3;
@@ -717,14 +709,24 @@ static int g2d_probe(struct platform_device *pdev)
 	of_id = of_match_node(exynos_g2d_match, pdev->dev.of_node);
 	if (!of_id) {
 		ret = -ENODEV;
-		goto unreg_video_dev;
+		goto free_m2m;
 	}
 	dev->variant = (struct g2d_variant *)of_id->data;
 
+	ret = video_register_device(vfd, VFL_TYPE_VIDEO, 0);
+	if (ret) {
+		v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
+		goto free_m2m;
+	}
+	video_set_drvdata(vfd, dev);
+	dev->vfd = vfd;
+	v4l2_info(&dev->v4l2_dev, "device registered as /dev/video%d\n",
+								vfd->num);
+
 	return 0;
 
-unreg_video_dev:
-	video_unregister_device(dev->vfd);
+free_m2m:
+	v4l2_m2m_release(dev->m2m_dev);
 rel_vdev:
 	video_device_release(vfd);
 unreg_v4l2_dev:
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-06-25 20:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-26 20:06 [PATCH] media: s5p-g2d: Fix a memory leak in an error handling path in 'g2d_probe()' Christophe JAILLET
2020-06-24 14:46 ` Hans Verkuil
2020-06-25 20:19 ` Christophe JAILLET

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).