diff mbox series

media: s5p-g2d: Fix a memory leak on ctx->fh.m2m_ctx

Message ID 1620706164-28856-1-git-send-email-dillon.minfei@gmail.com (mailing list archive)
State New, archived
Headers show
Series media: s5p-g2d: Fix a memory leak on ctx->fh.m2m_ctx | expand

Commit Message

Dillon Min May 11, 2021, 4:09 a.m. UTC
From: Dillon Min <dillon.minfei@gmail.com>

The m2m_ctx resources was allocated by v4l2_m2m_ctx_init() in g2d_open()
should be freed from g2d_release() when it's not used.

Fix it

Fixes: 918847341af0 ("[media] v4l: add G2D driver for s5p device family")
Signed-off-by: Dillon Min <dillon.minfei@gmail.com>
---
 drivers/media/platform/s5p-g2d/g2d.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Dillon Min May 25, 2021, 5:26 a.m. UTC | #1
Just a kind ping.

Thanks.
Dillon,

On Tue, May 11, 2021 at 12:09 PM <dillon.minfei@gmail.com> wrote:
>
> From: Dillon Min <dillon.minfei@gmail.com>
>
> The m2m_ctx resources was allocated by v4l2_m2m_ctx_init() in g2d_open()
> should be freed from g2d_release() when it's not used.
>
> Fix it
>
> Fixes: 918847341af0 ("[media] v4l: add G2D driver for s5p device family")
> Signed-off-by: Dillon Min <dillon.minfei@gmail.com>
> ---
>  drivers/media/platform/s5p-g2d/g2d.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
> index 15bcb7f6e113..0818fdd3e984 100644
> --- a/drivers/media/platform/s5p-g2d/g2d.c
> +++ b/drivers/media/platform/s5p-g2d/g2d.c
> @@ -279,6 +279,9 @@ static int g2d_release(struct file *file)
>         v4l2_ctrl_handler_free(&ctx->ctrl_handler);
>         v4l2_fh_del(&ctx->fh);
>         v4l2_fh_exit(&ctx->fh);
> +       mutex_lock(&dev->mutex);
> +       v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
> +       mutex_unlock(&dev->mutex);
>         kfree(ctx);
>         v4l2_info(&dev->v4l2_dev, "instance closed\n");
>         return 0;
> --
> 2.7.4
>
Hans Verkuil May 26, 2021, 1:41 p.m. UTC | #2
On 11/05/2021 06:09, dillon.minfei@gmail.com wrote:
> From: Dillon Min <dillon.minfei@gmail.com>
> 
> The m2m_ctx resources was allocated by v4l2_m2m_ctx_init() in g2d_open()
> should be freed from g2d_release() when it's not used.
> 
> Fix it
> 
> Fixes: 918847341af0 ("[media] v4l: add G2D driver for s5p device family")
> Signed-off-by: Dillon Min <dillon.minfei@gmail.com>
> ---
>  drivers/media/platform/s5p-g2d/g2d.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
> index 15bcb7f6e113..0818fdd3e984 100644
> --- a/drivers/media/platform/s5p-g2d/g2d.c
> +++ b/drivers/media/platform/s5p-g2d/g2d.c
> @@ -279,6 +279,9 @@ static int g2d_release(struct file *file)
>  	v4l2_ctrl_handler_free(&ctx->ctrl_handler);
>  	v4l2_fh_del(&ctx->fh);
>  	v4l2_fh_exit(&ctx->fh);
> +	mutex_lock(&dev->mutex);
> +	v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
> +	mutex_unlock(&dev->mutex);

This should be moved up to just before the v4l2_ctrl_handler_free() call.

Regards,

	Hans

>  	kfree(ctx);
>  	v4l2_info(&dev->v4l2_dev, "instance closed\n");
>  	return 0;
>
Dillon Min May 26, 2021, 3:13 p.m. UTC | #3
Hi Hans,

Thanks for the reply.

On Wed, May 26, 2021 at 9:41 PM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
>
> On 11/05/2021 06:09, dillon.minfei@gmail.com wrote:
> > From: Dillon Min <dillon.minfei@gmail.com>
> >
> > The m2m_ctx resources was allocated by v4l2_m2m_ctx_init() in g2d_open()
> > should be freed from g2d_release() when it's not used.
> >
> > Fix it
> >
> > Fixes: 918847341af0 ("[media] v4l: add G2D driver for s5p device family")
> > Signed-off-by: Dillon Min <dillon.minfei@gmail.com>
> > ---
> >  drivers/media/platform/s5p-g2d/g2d.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
> > index 15bcb7f6e113..0818fdd3e984 100644
> > --- a/drivers/media/platform/s5p-g2d/g2d.c
> > +++ b/drivers/media/platform/s5p-g2d/g2d.c
> > @@ -279,6 +279,9 @@ static int g2d_release(struct file *file)
> >       v4l2_ctrl_handler_free(&ctx->ctrl_handler);
> >       v4l2_fh_del(&ctx->fh);
> >       v4l2_fh_exit(&ctx->fh);
> > +     mutex_lock(&dev->mutex);
> > +     v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
> > +     mutex_unlock(&dev->mutex);
>
> This should be moved up to just before the v4l2_ctrl_handler_free() call.

On my mistake, thanks for pointing it out. will be moved up to
v4l2_ctrl_handler_free() in v2.

Best regards.
Dillon

>
> Regards,
>
>         Hans
>
> >       kfree(ctx);
> >       v4l2_info(&dev->v4l2_dev, "instance closed\n");
> >       return 0;
> >
>
diff mbox series

Patch

diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
index 15bcb7f6e113..0818fdd3e984 100644
--- a/drivers/media/platform/s5p-g2d/g2d.c
+++ b/drivers/media/platform/s5p-g2d/g2d.c
@@ -279,6 +279,9 @@  static int g2d_release(struct file *file)
 	v4l2_ctrl_handler_free(&ctx->ctrl_handler);
 	v4l2_fh_del(&ctx->fh);
 	v4l2_fh_exit(&ctx->fh);
+	mutex_lock(&dev->mutex);
+	v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
+	mutex_unlock(&dev->mutex);
 	kfree(ctx);
 	v4l2_info(&dev->v4l2_dev, "instance closed\n");
 	return 0;