[PATCH] media: s3c-camif: Avoid inappropriate kfree()

Katya Orlova posted 1 patch 2 years, 3 months ago
There is a newer version of this series
drivers/media/platform/samsung/s3c-camif/camif-capture.c | 1 -
1 file changed, 1 deletion(-)
[PATCH] media: s3c-camif: Avoid inappropriate kfree()
Posted by Katya Orlova 2 years, 3 months ago
s3c_camif_register_video_node() works with video_device structure stored
as a field of camif_vp,
so it should not be kfreed. But there is video_device_release() on error
path that do it.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: babde1c243b2 ("[media] V4L: Add driver for S3C24XX/S3C64XX SoC series camera interface")
Signed-off-by: Katya Orlova <e.orlova@ispras.ru>
---
 drivers/media/platform/samsung/s3c-camif/camif-capture.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/media/platform/samsung/s3c-camif/camif-capture.c b/drivers/media/platform/samsung/s3c-camif/camif-capture.c
index 76634d242b10..79c8ee845c38 100644
--- a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/samsung/s3c-camif/camif-capture.c
@@ -1172,7 +1172,6 @@ int s3c_camif_register_video_node(struct camif_dev *camif, int idx)
 err_me_cleanup:
 	media_entity_cleanup(&vfd->entity);
 err_vd_rel:
-	video_device_release(vfd);
 	return ret;
 }
 
-- 
2.30.2
Re: [PATCH] media: s3c-camif: Avoid inappropriate kfree()
Posted by Andi Shyti 2 years, 3 months ago
Hi Katya,

On Thu, Aug 24, 2023 at 12:07:25PM +0300, Katya Orlova wrote:
> s3c_camif_register_video_node() works with video_device structure stored
> as a field of camif_vp,
> so it should not be kfreed. But there is video_device_release() on error
> path that do it.

that's correct, the video_device is allocated with the camif_dev
allocation.

> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: babde1c243b2 ("[media] V4L: Add driver for S3C24XX/S3C64XX SoC series camera interface")
> Signed-off-by: Katya Orlova <e.orlova@ispras.ru>
> ---
>  drivers/media/platform/samsung/s3c-camif/camif-capture.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/media/platform/samsung/s3c-camif/camif-capture.c b/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> index 76634d242b10..79c8ee845c38 100644
> --- a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> +++ b/drivers/media/platform/samsung/s3c-camif/camif-capture.c
> @@ -1172,7 +1172,6 @@ int s3c_camif_register_video_node(struct camif_dev *camif, int idx)
>  err_me_cleanup:
>  	media_entity_cleanup(&vfd->entity);
>  err_vd_rel:
> -	video_device_release(vfd);

The best fix, though, is to completely get rid of the
"err_vd_rel" goto label. You mind doint that on a v2?

Thanks,
Andi

>  	return ret;
>  }
>  
> -- 
> 2.30.2
>
[PATCH v2] media: s3c-camif: Avoid inappropriate kfree()
Posted by Katya Orlova 2 years, 2 months ago
s3c_camif_register_video_node() works with video_device structure stored
as a field of camif_vp, so it should not be kfreed.
But there is video_device_release() on error path that do it.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: babde1c243b2 ("[media] V4L: Add driver for S3C24XX/S3C64XX SoC series camera interface")
Signed-off-by: Katya Orlova <e.orlova@ispras.ru>
---
v2: Get rid not only of video_device_release(), but of the entire
"err_vd_rel" goto label, as Andi Shyti <andi.shyti@kernel.org> suggested.
 drivers/media/platform/samsung/s3c-camif/camif-capture.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/samsung/s3c-camif/camif-capture.c b/drivers/media/platform/samsung/s3c-camif/camif-capture.c
index 76634d242b10..0f5b3845d7b9 100644
--- a/drivers/media/platform/samsung/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/samsung/s3c-camif/camif-capture.c
@@ -1133,12 +1133,12 @@ int s3c_camif_register_video_node(struct camif_dev *camif, int idx)
 
 	ret = vb2_queue_init(q);
 	if (ret)
-		goto err_vd_rel;
+		return ret;
 
 	vp->pad.flags = MEDIA_PAD_FL_SINK;
 	ret = media_entity_pads_init(&vfd->entity, 1, &vp->pad);
 	if (ret)
-		goto err_vd_rel;
+		return ret;
 
 	video_set_drvdata(vfd, vp);
 
@@ -1171,8 +1171,6 @@ int s3c_camif_register_video_node(struct camif_dev *camif, int idx)
 	v4l2_ctrl_handler_free(&vp->ctrl_handler);
 err_me_cleanup:
 	media_entity_cleanup(&vfd->entity);
-err_vd_rel:
-	video_device_release(vfd);
 	return ret;
 }
 
-- 
2.30.2