osd: null pointer risk protect
authorPengcheng Chen <pengcheng.chen@amlogic.com>
Wed, 11 Oct 2017 03:06:34 +0000 (11:06 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Thu, 12 Oct 2017 02:17:34 +0000 (19:17 -0700)
PD#151241: null pointer risk protect

driver defect clean up:
#284

Change-Id: I05ffb3df451b0f62de0ef00a688edc6bc33b1964
Signed-off-by: Pengcheng Chen <pengcheng.chen@amlogic.com>
drivers/amlogic/media/osd/osd_fb.c

index 40e74c7..587b8b9 100644 (file)
@@ -1277,7 +1277,7 @@ static int osd_mmap(struct fb_info *info, struct vm_area_struct *vma)
                fbdev->fb_mem_vaddr = fb_rmem_vaddr[fb_index];
                if (!fbdev->fb_mem_vaddr) {
                        osd_log_err("failed to ioremap frame buffer\n");
-                       ret = -ENOMEM;
+                       return -ENOMEM;
                }
                osd_log_info("Frame buffer memory assigned at");
                osd_log_info(" %d, phy: 0x%p, vir:0x%p, size=%dK\n\n",
@@ -1318,7 +1318,8 @@ static int osd_mmap(struct fb_info *info, struct vm_area_struct *vma)
                        osd_log_info("---------------clear fb%d memory %p\n",
                                fb_index, fbdev->fb_mem_vaddr);
                        set_logo_loaded();
-                       memset(fbdev->fb_mem_vaddr, 0x0, fbdev->fb_len);
+                       if (fbdev->fb_mem_vaddr)
+                               memset(fbdev->fb_mem_vaddr, 0x0, fbdev->fb_len);
                        if (fb_index == DEV_OSD0 && osd_get_afbc()) {
                                for (j = 1; j < OSD_MAX_BUF_NUM; j++) {
                                        osd_log_info(
@@ -1334,10 +1335,10 @@ static int osd_mmap(struct fb_info *info, struct vm_area_struct *vma)
                                 * 1. the big buffer ion alloc
                                 * 2. reserved memory
                                 */
-
-                               memset(fb_rmem_vaddr[fb_index],
-                                               0x0,
-                                               fb_rmem_size[fb_index]);
+                               if (fb_rmem_vaddr[fb_index])
+                                       memset(fb_rmem_vaddr[fb_index],
+                                                       0x0,
+                                                       fb_rmem_size[fb_index]);
                        }
                        /* setup osd if not logo layer */
                        osddev_setup(fbdev);