Skip to contentSkip to conversation

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

PATCH Superseded [email protected] 2 participants 4 messages May 11, 2021 – May 26, 2021 Media (V4L/DVB)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

From: Dillon Min <[email protected]>

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")
---
 drivers/media/platform/s5p-g2d/g2d.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/media/platform/s5p-g2d/g2d.c +3 -0
index 15bcb7f6e113..0818fdd3e984 100644
@@ -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;
Signature · 1 line
2.7.4
author
#1 lore raw

Just a kind ping.

Thanks.
Dillon,

Quoted 31 lines · On Tue, May 11, 2021 at 12:09 PM <[email protected]> wrote:

From: Dillon Min <[email protected]>

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")
---
 drivers/media/platform/s5p-g2d/g2d.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/media/platform/s5p-g2d/g2d.c +3 -1
index 15bcb7f6e113..0818fdd3e984 100644
@@ -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

#2 lore raw
In reply to [email protected]
Quoted 18 lines · On 11/05/2021 06:09, [email protected] wrote:

From: Dillon Min <[email protected]>

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")
---
 drivers/media/platform/s5p-g2d/g2d.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/media/platform/s5p-g2d/g2d.c +0 -0
index 15bcb7f6e113..0818fdd3e984 100644

drivers/media/platform/s5p-g2d/g2d.c static int g2d_release(struct file *file) · line 284

Quoted 6 lines
drivers/media/platform/s5p-g2d/g2d.c +3 -0
@@ -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

Quoted 4 lines
drivers/media/platform/s5p-g2d/g2d.c +0 -0
 	kfree(ctx);
 	v4l2_info(&dev->v4l2_dev, "instance closed\n");
 	return 0;
author
#3 lore raw

Hi Hans,

Thanks for the reply.

Quoted 15 lines · Hans Verkuil
Quoted 13 lines · On 11/05/2021 06:09, [email protected] wrote:

From: Dillon Min <[email protected]>

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")
---
 drivers/media/platform/s5p-g2d/g2d.c | 3 +++
 1 file changed, 3 insertions(+)
Quoted 13 lines

drivers/media/platform/s5p-g2d/g2d.c static int g2d_release(struct file *file) · line 284

Quoted 11 lines
drivers/media/platform/s5p-g2d/g2d.c +3 -0
index 15bcb7f6e113..0818fdd3e984 100644
@@ -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

Quoted 10 lines

Regards,

Hans

Quoted 4 lines
drivers/media/platform/s5p-g2d/g2d.c +0 -0
      kfree(ctx);
      v4l2_info(&dev->v4l2_dev, "instance closed\n");
      return 0;