[PATCH] media: s5p-g2d: Fix a memory leak in an error handling path in 'g2d_probe()'

Hans Verkuil hverkuil at xs4all.nl
Wed Jun 24 10:46:04 EDT 2020


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 at 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



More information about the linux-arm-kernel mailing list