ge2d: fix ge2d coverity issue [1/1]
authorCao Jian <jian.cao@amlogic.com>
Thu, 14 Nov 2019 14:02:28 +0000 (22:02 +0800)
committerJian Cao <jian.cao@amlogic.com>
Mon, 9 Dec 2019 06:53:27 +0000 (23:53 -0700)
PD#SWPL-13975

Problem:
coverity defect cleanup for ge2d

Solution:
DEADCODE on aml_dmabuf_ops_attach()
RESOURCE_LEAK on aml_dma_alloc()
REVERSE_INULL on aml_dma_mmap()
USE_AFTER_FREE on aml_dma_put()
COPY_PASTE_ERROR&FORWARD_NULL on build_ge2d_config()

Verify:
coverity check

Change-Id: I1b80cb993254adb1721dfb2e5b25db0248dca1a6
Signed-off-by: Cao Jian <jian.cao@amlogic.com>
(cherry picked from commit 801723a61128d84861d64ee5336e6054169fea8b)

drivers/amlogic/media/common/ge2d/ge2d_dmabuf.c
drivers/amlogic/media/common/ge2d/ge2d_wq.c

index e397caa1fc2e11c9d680c3b607e370e833b4ee89..c5502f25f2127b6085075d232d140e5653286550 100644 (file)
@@ -102,9 +102,9 @@ static void aml_dma_put(void *buf_priv)
        buf->vaddr = NULL;
        clear_dma_buffer((struct aml_dma_buffer *)buf->priv, buf->index);
        put_device(buf->dev);
-       kfree(buf);
        ge2d_log_dbg("ge2d free:aml_dma_buf=0x%p,buf->index=%d\n",
                buf, buf->index);
+       kfree(buf);
 }
 
 static void *aml_dma_alloc(struct device *dev, unsigned long attrs,
@@ -129,6 +129,7 @@ static void *aml_dma_alloc(struct device *dev, unsigned long attrs,
        if (cma_pages) {
                paddr = page_to_phys(cma_pages);
        } else {
+               kfree(buf);
                pr_err("failed to alloc cma pages.\n");
                return NULL;
        }
@@ -148,7 +149,7 @@ static int aml_dma_mmap(void *buf_priv, struct vm_area_struct *vma)
 {
        struct aml_dma_buf *buf = buf_priv;
        unsigned long pfn = 0;
-       unsigned long vsize = vma->vm_end - vma->vm_start;
+       unsigned long vsize;
        int ret = -1;
 
        if (!buf || !vma) {
@@ -156,6 +157,8 @@ static int aml_dma_mmap(void *buf_priv, struct vm_area_struct *vma)
                return -EINVAL;
        }
 
+       vsize = vma->vm_end - vma->vm_start;
+
        pfn = buf->dma_addr >> PAGE_SHIFT;
        ret = remap_pfn_range(vma, vma->vm_start, pfn,
                vsize, vma->vm_page_prot);
@@ -206,11 +209,6 @@ static int aml_dmabuf_ops_attach(struct dma_buf *dbuf, struct device *dev,
        for_each_sg(sgt->sgl, sg, sgt->nents, i) {
                struct page *page = phys_to_page(phys);
 
-               if (!page) {
-                       sg_free_table(sgt);
-                       kfree(attach);
-                       return -ENOMEM;
-               }
                sg_set_page(sg, page, PAGE_SIZE, 0);
                phys += PAGE_SIZE;
        }
index 3e35319206f3df15255128f67390387aa7f4371e..b775f27684a955f071b75511cb2ff407a8128201 100644 (file)
@@ -806,7 +806,7 @@ static int build_ge2d_config(struct ge2d_context_s *context,
                                        update_canvas_cfg(canvas_cfg,
                                                cfg->dst_planes[i].addr,
                                                cfg->dst_planes[i].w *
-                                               src->bpp / 8,
+                                               dst->bpp / 8,
                                                cfg->dst_planes[i].h);
                                }
                        }
@@ -824,7 +824,8 @@ static int setup_display_property(struct src_dst_para_s *src_dst, int index)
        u32 cs_width = 0, cs_height = 0, cs_addr = 0;
        unsigned        int     data32;
        unsigned        int     bpp;
-       unsigned int    block_mode[] = {2, 4, 8, 16, 16, 32, 0, 24};
+       unsigned int    block_mode[] = {2, 4, 8, 16, 16, 32, 0, 24,
+                                       0, 0, 0, 0, 0, 0, 0, 0};
 
        src_dst->canvas_index = index;
        if (ge2d_meson_dev.canvas_status == 0) {