6e42556247507284f1396d1808f3ff00336ebdda
[openwrt/staging/xback.git] /
1 From db7b984f1957e5a26775a62a78e60df3f2da671f 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 detaching
5 dmabuf
6
7 When importing there was a missing call to detach the buffer,
8 so each import leaked the sg table entry.
9
10 Actually the release process for both locally allocated and
11 imported buffers is identical, so fix them to both use the same
12 function.
13
14 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
15 ---
16 .../staging/vc04_services/vc-sm-cma/vc_sm.c | 22 ++-----------------
17 1 file changed, 2 insertions(+), 20 deletions(-)
18
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
22
23 /*
24 * Cleans up imported dmabuf.
25 + * Should be called with mutex held.
26 */
27 static void vc_sm_clean_up_dmabuf(struct vc_sm_buffer *buffer)
28 {
29 @@ -244,7 +245,6 @@ static void vc_sm_clean_up_dmabuf(struct
30 return;
31
32 /* Handle cleaning up imported dmabufs */
33 - mutex_lock(&buffer->lock);
34 if (buffer->import.sgt) {
35 dma_buf_unmap_attachment(buffer->import.attach,
36 buffer->import.sgt,
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;
40 }
41 - mutex_unlock(&buffer->lock);
42 }
43
44 /*
45 @@ -673,23 +672,6 @@ int vc_sm_import_dmabuf_mmap(struct dma_
46 }
47
48 static
49 -void vc_sm_import_dma_buf_release(struct dma_buf *dmabuf)
50 -{
51 - struct vc_sm_buffer *buf = dmabuf->priv;
52 -
53 - pr_debug("%s: Relasing dma_buf %p\n", __func__, dmabuf);
54 - mutex_lock(&buf->lock);
55 - if (!buf->imported)
56 - return;
57 -
58 - buf->in_use = 0;
59 -
60 - vc_sm_vpu_free(buf);
61 -
62 - vc_sm_release_resource(buf);
63 -}
64 -
65 -static
66 int vc_sm_import_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
67 enum dma_data_direction direction)
68 {
69 @@ -717,7 +699,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,