1 From 6ff310748f67d98d1c2c8ea75decd9dee13aa50c Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 4 Nov 2020 18:54:20 +0000
4 Subject: [PATCH] staging: vcsm-cma: Fix memory leak from not
7 When importing there was a missing call to detach the buffer,
8 so each import leaked the sg table entry.
10 Actually the release process for both locally allocated and
11 imported buffers is identical, so fix them to both use the same
14 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
16 .../staging/vc04_services/vc-sm-cma/vc_sm.c | 22 ++-----------------
17 1 file changed, 2 insertions(+), 20 deletions(-)
19 --- a/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
20 +++ b/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
21 @@ -237,6 +237,7 @@ static void vc_sm_add_resource(struct vc
24 * Cleans up imported dmabuf.
25 + * Should be called with mutex held.
27 static void vc_sm_clean_up_dmabuf(struct vc_sm_buffer *buffer)
29 @@ -244,7 +245,6 @@ static void vc_sm_clean_up_dmabuf(struct
32 /* Handle cleaning up imported dmabufs */
33 - mutex_lock(&buffer->lock);
34 if (buffer->import.sgt) {
35 dma_buf_unmap_attachment(buffer->import.attach,
37 @@ -255,7 +255,6 @@ static void vc_sm_clean_up_dmabuf(struct
38 dma_buf_detach(buffer->dma_buf, buffer->import.attach);
39 buffer->import.attach = NULL;
41 - mutex_unlock(&buffer->lock);
45 @@ -687,23 +686,6 @@ int vc_sm_import_dmabuf_mmap(struct dma_
49 -void vc_sm_import_dma_buf_release(struct dma_buf *dmabuf)
51 - struct vc_sm_buffer *buf = dmabuf->priv;
53 - pr_debug("%s: Relasing dma_buf %p\n", __func__, dmabuf);
54 - mutex_lock(&buf->lock);
60 - vc_sm_vpu_free(buf);
62 - vc_sm_release_resource(buf);
66 void *vc_sm_import_dma_buf_kmap(struct dma_buf *dmabuf,
69 @@ -753,7 +735,7 @@ static const struct dma_buf_ops dma_buf_
70 .map_dma_buf = vc_sm_import_map_dma_buf,
71 .unmap_dma_buf = vc_sm_import_unmap_dma_buf,
72 .mmap = vc_sm_import_dmabuf_mmap,
73 - .release = vc_sm_import_dma_buf_release,
74 + .release = vc_sm_dma_buf_release,
75 .attach = vc_sm_import_dma_buf_attach,
76 .detach = vc_sm_import_dma_buf_detatch,
77 .begin_cpu_access = vc_sm_import_dma_buf_begin_cpu_access,