gdc: ge2d: fix ge2d dma-buf no free memory issue [1/1]
authorPengcheng Chen <pengcheng.chen@amlogic.com>
Mon, 4 Mar 2019 04:43:49 +0000 (12:43 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Mon, 18 Mar 2019 12:25:40 +0000 (04:25 -0800)
PD#SWPL-5685

Problem:
gdc&ge2d dma buf memory leak

Solution:
clear dmabuf alloc flag when dmabuf really free

Verify:
verified by w400

Change-Id: I914d93d795311fd6e3e34ca5bd64aaf4db3d4c7a
Signed-off-by: Pengcheng Chen <pengcheng.chen@amlogic.com>
drivers/amlogic/media/common/ge2d/ge2d_dmabuf.c
drivers/amlogic/media/common/ge2d/ge2d_dmabuf.h
drivers/amlogic/media/gdc/app/gdc_dmabuf.c
drivers/amlogic/media/gdc/app/gdc_dmabuf.h

index 046cb1e..2e8a8a7 100644 (file)
 #include "ge2d_log.h"
 #include "ge2d_dmabuf.h"
 
+static void clear_dma_buffer(struct aml_dma_buffer *buffer, int index);
 /* dma free*/
 static void aml_dma_put(void *buf_priv)
 {
        struct aml_dma_buf *buf = buf_priv;
 
        if (!atomic_dec_and_test(&buf->refcount)) {
-               ge2d_log_dbg("aml_dma_put, refcont=%d\n",
+               ge2d_log_dbg("ge2d aml_dma_put, refcont=%d\n",
                        atomic_read(&buf->refcount));
                return;
        }
@@ -49,9 +50,10 @@ static void aml_dma_put(void *buf_priv)
        }
        dma_free_attrs(buf->dev, buf->size, buf->cookie, buf->dma_addr,
                       buf->attrs);
+       clear_dma_buffer((struct aml_dma_buffer *)buf->priv, buf->index);
        put_device(buf->dev);
        kfree(buf);
-       ge2d_log_dbg("aml_dma_put free!\n");
+       ge2d_log_dbg("ge2d aml_dma_put free!\n");
 }
 
 static void *aml_dma_alloc(struct device *dev, unsigned long attrs,
@@ -339,6 +341,11 @@ static int find_empty_dma_buffer(struct aml_dma_buffer *buffer)
                return -1;
 }
 
+static void clear_dma_buffer(struct aml_dma_buffer *buffer, int index)
+{
+       buffer->gd_buffer[index].alloc = 0;
+}
+
 void *ge2d_dma_buffer_create(void)
 {
        int i;
@@ -391,7 +398,8 @@ int ge2d_dma_buffer_alloc(struct aml_dma_buffer *buffer,
                GFP_HIGHUSER | __GFP_ZERO);
        if (!buf)
                return (-ENOMEM);
-
+       ((struct aml_dma_buf *)buf)->priv = buffer;
+       ((struct aml_dma_buf *)buf)->index = index;
        mutex_lock(&(buffer->lock));
        buffer->gd_buffer[index].mem_priv = buf;
        buffer->gd_buffer[index].index = index;
@@ -416,7 +424,6 @@ int ge2d_dma_buffer_free(struct aml_dma_buffer *buffer, int index)
                return (-EINVAL);
        }
        aml_dma_put(buf);
-       buffer->gd_buffer[index].alloc = 0;
        return 0;
 }
 
@@ -515,7 +522,7 @@ int ge2d_dma_buffer_map(struct aml_dma_cfg *cfg)
        cfg->attach = d_att;
        cfg->vaddr = vaddr;
        cfg->sg = sg;
-       ge2d_log_dbg("%s\n", __func__);
+       ge2d_log_dbg("%s, dbuf=0x%p\n", __func__, dbuf);
        return ret;
 
 vmap_err:
@@ -587,7 +594,7 @@ void ge2d_dma_buffer_unmap(struct aml_dma_cfg *cfg)
 
        dma_buf_put(dbuf);
 
-       ge2d_log_dbg("%s\n", __func__);
+       ge2d_log_dbg("%s, dbuf=0x%p\n", __func__, dbuf);
 }
 
 void ge2d_dma_buffer_dma_flush(struct device *dev, int fd)
index 85dc94b..396a6a8 100644 (file)
@@ -40,6 +40,7 @@ struct aml_dma_buf {
        struct sg_table         *sgt_base;
        /* DMABUF related */
        struct dma_buf_attachment       *db_attach;
+       void                *priv;
 };
 
 struct aml_dma_buf_priv {
index 390874a..624fe7b 100644 (file)
 #include "system_log.h"
 #include "gdc_dmabuf.h"
 
+static void clear_dma_buffer(struct aml_dma_buffer *buffer, int index);
 /* dma free*/
 static void aml_dma_put(void *buf_priv)
 {
        struct aml_dma_buf *buf = buf_priv;
 
        if (!atomic_dec_and_test(&buf->refcount)) {
-               gdc_log(LOG_INFO, "aml_dma_put, refcont=%d\n",
+               gdc_log(LOG_INFO, "gdc aml_dma_put, refcont=%d\n",
                        atomic_read(&buf->refcount));
                return;
        }
@@ -50,9 +51,10 @@ static void aml_dma_put(void *buf_priv)
        }
        dma_free_attrs(buf->dev, buf->size, buf->cookie, buf->dma_addr,
                       buf->attrs);
+       clear_dma_buffer((struct aml_dma_buffer *)buf->priv, buf->index);
        put_device(buf->dev);
        kfree(buf);
-       gdc_log(LOG_INFO, "aml_dma_put free!\n");
+       gdc_log(LOG_INFO, "gdc aml_dma_put free!\n");
 }
 
 static void *aml_dma_alloc(struct device *dev, unsigned long attrs,
@@ -341,6 +343,11 @@ static int find_empty_dma_buffer(struct aml_dma_buffer *buffer)
                return -1;
 }
 
+static void clear_dma_buffer(struct aml_dma_buffer *buffer, int index)
+{
+       buffer->gd_buffer[index].alloc = 0;
+}
+
 void *gdc_dma_buffer_create(void)
 {
        int i;
@@ -393,7 +400,8 @@ int gdc_dma_buffer_alloc(struct aml_dma_buffer *buffer,
                GFP_HIGHUSER | __GFP_ZERO);
        if (!buf)
                return (-ENOMEM);
-
+       ((struct aml_dma_buf *)buf)->priv = buffer;
+       ((struct aml_dma_buf *)buf)->index = index;
        mutex_lock(&(buffer->lock));
        buffer->gd_buffer[index].mem_priv = buf;
        buffer->gd_buffer[index].index = index;
@@ -418,7 +426,6 @@ int gdc_dma_buffer_free(struct aml_dma_buffer *buffer, int index)
                return (-EINVAL);
        }
        aml_dma_put(buf);
-       buffer->gd_buffer[index].alloc = 0;
        return 0;
 }
 
@@ -476,6 +483,7 @@ int gdc_dma_buffer_map(struct aml_dma_cfg *cfg)
        struct device *dev = NULL;
        enum dma_data_direction dir;
 
+
        if (cfg == NULL || (cfg->fd < 0) || cfg->dev == NULL) {
                pr_err("error input param");
                return -EINVAL;
@@ -517,6 +525,7 @@ int gdc_dma_buffer_map(struct aml_dma_cfg *cfg)
        cfg->attach = d_att;
        cfg->vaddr = vaddr;
        cfg->sg = sg;
+       gdc_log(LOG_INFO, "gdc_dma_buffer_map, dbuf=0x%p\n", dbuf);
 
        return ret;
 
@@ -589,6 +598,7 @@ void gdc_dma_buffer_unmap(struct aml_dma_cfg *cfg)
        dma_buf_detach(dbuf, d_att);
 
        dma_buf_put(dbuf);
+       gdc_log(LOG_INFO, "gdc_dma_buffer_unmap, dbuf=0x%p\n", dbuf);
 }
 
 void gdc_dma_buffer_dma_flush(struct device *dev, int fd)
index 6de1d57..fb039b4 100644 (file)
@@ -38,6 +38,7 @@ struct aml_dma_buf {
        struct sg_table         *sgt_base;
        /* DMABUF related */
        struct dma_buf_attachment       *db_attach;
+       void                *priv;
 };
 
 struct aml_dma_buf_priv {