vdin: change "IS_ERR" invoking to "IS_ERR_OR_NULL" [1/1]
authorzhiwei.yuan <zhiwei.yuan@amlogic.com>
Tue, 22 Oct 2019 08:28:39 +0000 (16:28 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Mon, 28 Oct 2019 03:02:35 +0000 (20:02 -0700)
PD#SWPL-15522

Problem:
kernel panic caused by NULL pointer

Solution:
check pointer before access members of structure

Verify:
verified by t962x2_x301

Change-Id: Ia20192bb88d90b06d43c04e6e4e6aa37b2862aa2
Signed-off-by: zhiwei.yuan <zhiwei.yuan@amlogic.com>
drivers/amlogic/media/vin/tvin/vdin/vdin_debug.c
drivers/amlogic/media/vin/tvin/vdin/vdin_drv.c

index 64d6c0ac90c07e0c73e87c6f7ee09b55dc544706..ee87bb55c45b975b9afb01845682920daa061ead 100644 (file)
@@ -248,8 +248,8 @@ static void vdin_dump_one_buf_mem(char *path, struct vdin_dev_s *devp,
        set_fs(KERNEL_DS);
        filp = filp_open(path, O_RDWR|O_CREAT, 0666);
 
-       if (IS_ERR(filp)) {
-               pr_info("create %s error.\n", path);
+       if (IS_ERR_OR_NULL(filp)) {
+               pr_info("create %s error or filp is NULL.\n", path);
                return;
        }
        if ((devp->cma_config_flag & 0x1) &&
@@ -345,8 +345,8 @@ static void vdin_dump_mem(char *path, struct vdin_dev_s *devp)
        mem_size = (loff_t)devp->canvas_active_w * devp->canvas_h;
        for (i = 0; i < VDIN_CANVAS_MAX_CNT; i++)
                vfbuf[i] = NULL;
-       if (IS_ERR(filp)) {
-               pr_info("create %s error.\n", path);
+       if (IS_ERR_OR_NULL(filp)) {
+               pr_info("create %s error or filp is NULL.\n", path);
                return;
        }
        if ((devp->cma_config_flag & 0x1) &&
@@ -523,8 +523,8 @@ static void vdin_dump_one_afbce_mem(char *path, struct vdin_dev_s *devp,
        }
        strcat(buff, "_1header.bin");
        filp = filp_open(buff, O_RDWR|O_CREAT, 0666);
-       if (IS_ERR(filp)) {
-               pr_info("create %s header error.\n", buff);
+       if (IS_ERR_OR_NULL(filp)) {
+               pr_info("create %s header error or filp is NULL.\n", buff);
                return;
        }
 
@@ -544,8 +544,8 @@ static void vdin_dump_one_afbce_mem(char *path, struct vdin_dev_s *devp,
        strcpy(buff, path);
        strcat(buff, "_1table.bin");
        filp = filp_open(buff, O_RDWR|O_CREAT, 0666);
-       if (IS_ERR(filp)) {
-               pr_info("create %s table error.\n", buff);
+       if (IS_ERR_OR_NULL(filp)) {
+               pr_info("create %s table error or filp is NULL.\n", buff);
                return;
        }
        vdin_dma_flush(devp, buf_table,
@@ -564,8 +564,8 @@ static void vdin_dump_one_afbce_mem(char *path, struct vdin_dev_s *devp,
        strcpy(buff, path);
        strcat(buff, "_1body.bin");
        filp = filp_open(buff, O_RDWR|O_CREAT, 0666);
-       if (IS_ERR(filp)) {
-               pr_info("create %s body error.\n", buff);
+       if (IS_ERR_OR_NULL(filp)) {
+               pr_info("create %s body error or filp is NULL.\n", buff);
                return;
        }
        if (highmem_flag == 0) {
@@ -622,8 +622,8 @@ static void dump_other_mem(char *path,
        set_fs(KERNEL_DS);
        filp = filp_open(path, O_RDWR|O_CREAT, 0666);
 
-       if (IS_ERR(filp)) {
-               pr_info("create %s error.\n", path);
+       if (IS_ERR_OR_NULL(filp)) {
+               pr_info("create %s error or filp is NULL.\n", path);
                return;
        }
        buf = phys_to_virt(start);
@@ -1078,8 +1078,8 @@ static void vdin_write_afbce_mem(struct vdin_dev_s *devp, char *type,
        set_fs(KERNEL_DS);
        pr_info("head bin file path = %s\n", md_path_head);
        filp = filp_open(md_path_head, O_RDONLY, 0);
-       if (IS_ERR(filp)) {
-               pr_info("read %s error.\n", md_path_head);
+       if (IS_ERR_OR_NULL(filp)) {
+               pr_info("read %s error or filp is NULL.\n", md_path_head);
                return;
        }
 
@@ -1097,8 +1097,8 @@ static void vdin_write_afbce_mem(struct vdin_dev_s *devp, char *type,
        set_fs(KERNEL_DS);
        pr_info("body bin file path = %s\n", md_path_body);
        filp = filp_open(md_path_body, O_RDONLY, 0);
-       if (IS_ERR(filp)) {
-               pr_info("read %s error.\n", md_path_body);
+       if (IS_ERR_OR_NULL(filp)) {
+               pr_info("read %s error or filp is NULL.\n", md_path_body);
                return;
        }
 
@@ -1169,8 +1169,8 @@ static void vdin_write_mem(
        set_fs(KERNEL_DS);
        pr_info("bin file path = %s\n", path);
        filp = filp_open(path, O_RDONLY, 0);
-       if (IS_ERR(filp)) {
-               pr_info("read %s error.\n", path);
+       if (IS_ERR_OR_NULL(filp)) {
+               pr_info("read %s error or filp is NULL.\n", path);
                return;
        }
        devp->curr_wr_vfe->vf.type = VIDTYPE_VIU_SINGLE_PLANE |
@@ -1241,8 +1241,8 @@ static void vdin_write_mem(
                set_fs(KERNEL_DS);
                pr_info("md file path = %s\n", md_path);
                md_flip = filp_open(md_path, O_RDONLY, 0);
-               if (IS_ERR(md_flip)) {
-                       pr_info("read %s error.\n", md_path);
+               if (IS_ERR_OR_NULL(md_flip)) {
+                       pr_info("read %s error or md_flip = NULL.\n", md_path);
                        return;
                }
                index = devp->curr_wr_vfe->vf.index & 0xff;
@@ -1295,8 +1295,8 @@ static void vdin_write_cont_mem(struct vdin_dev_s *devp, char *type,
        set_fs(KERNEL_DS);
        pr_info("bin file path = %s\n", path);
        filp = filp_open(path, O_RDONLY, 0);
-       if (IS_ERR(filp)) {
-               pr_info("read %s error.\n", path);
+       if (IS_ERR_OR_NULL(filp)) {
+               pr_info("read %s error or filp is NULL.\n", path);
                return;
        }
        for (i = 0; i < field_num; i++) {
index 397cd88f01cd2ac73fe62917aef44b0fbb8d14e4..9dcead4c3f231deffa477eea13e02c24dddb6c15 100644 (file)
@@ -824,9 +824,9 @@ int start_tvin_service(int no, struct vdin_parm_s  *para)
        enum tvin_sig_fmt_e fmt;
 
        mutex_lock(&devp->fe_lock);
-       if (IS_ERR(devp)) {
-               pr_err("[vdin]%s vdin%d has't registered,please register.\n",
-                               __func__, no);
+       if (IS_ERR_OR_NULL(devp)) {
+               pr_err("[vdin]%s vdin%d has't registered or devp is NULL\n",
+                      __func__, no);
                mutex_unlock(&devp->fe_lock);
                return -1;
        }
@@ -1043,9 +1043,9 @@ static int vdin_ioctl_fe(int no, struct fe_arg_s *parm)
 {
        struct vdin_dev_s *devp = vdin_devp[no];
        int ret = 0;
-       if (IS_ERR(devp)) {
-               pr_err("[vdin]%s vdin%d has't registered,please register.\n",
-                               __func__, no);
+       if (IS_ERR_OR_NULL(devp)) {
+               pr_err("[vdin]%s vdin%d has't registered or devp is NULL\n",
+                      __func__, no);
                return -1;
        }
        if (devp->frontend &&
@@ -2752,10 +2752,12 @@ static long vdin_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        pr_info("TVIN_IOC_GET_ALLM_MODE err\n\n");
                        break;
                }
-               pr_info("allm mode-%d,IT=%d,CN=%d\n\n",
-                       devp->prop.latency.allm_mode,
-                       devp->prop.latency.it_content,
-                       devp->prop.latency.cn_type);
+
+               if (vdin_dbg_en)
+                       pr_info("allm mode-%d,IT=%d,CN=%d\n\n",
+                               devp->prop.latency.allm_mode,
+                               devp->prop.latency.it_content,
+                               devp->prop.latency.cn_type);
                mutex_unlock(&devp->fe_lock);
                break;
        case TVIN_IOC_G_VDIN_HIST:
@@ -3154,8 +3156,8 @@ static int vdin_drv_probe(struct platform_device *pdev)
                goto fail_add_cdev;
        }
        vdevp->dev = vdin_create_device(&pdev->dev, vdevp->index);
-       if (IS_ERR(vdevp->dev)) {
-               pr_err("%s: failed to create device. !!!!!!!!!!\n", __func__);
+       if (IS_ERR_OR_NULL(vdevp->dev)) {
+               pr_err("%s: failed to create device. or dev=NULL\n", __func__);
                ret = PTR_ERR(vdevp->dev);
                goto fail_create_device;
        }
@@ -3589,9 +3591,9 @@ static int __init vdin_drv_init(void)
        pr_info("%s: major %d\n", __func__, MAJOR(vdin_devno));
 
        vdin_clsp = class_create(THIS_MODULE, VDIN_CLS_NAME);
-       if (IS_ERR(vdin_clsp)) {
+       if (IS_ERR_OR_NULL(vdin_clsp)) {
                ret = PTR_ERR(vdin_clsp);
-               pr_err("%s: failed to create class\n", __func__);
+               pr_err("%s: failed to create class or ret=NULL\n", __func__);
                goto fail_class_create;
        }
 #ifdef DEBUG_SUPPORT