cvbsout: cvbsout/vdac coverity fix
authorNian Jing <nian.jing@amlogic.com>
Wed, 20 Jun 2018 05:56:47 +0000 (13:56 +0800)
committerYixun Lan <yixun.lan@amlogic.com>
Wed, 20 Jun 2018 09:56:57 +0000 (02:56 -0700)
PD#168730: coverity fix

Change-Id: I0753c4ae9a4eed14a46a1f2bcda4cc11fbb0b351
Signed-off-by: Nian Jing <nian.jing@amlogic.com>
drivers/amlogic/media/vout/cvbs/cvbs_out.c
drivers/amlogic/media/vout/cvbs/wss.c

index 9c88d27554a62a547cd31f944ed55a0cba22930e..3cc0fe748f395ff2cb8f43d93f66152b5e2b7878 100644 (file)
@@ -374,13 +374,15 @@ int cvbs_out_setmode(void)
 {
        int ret;
 
-       if (local_cvbs_mode >= MODE_MAX)
-               cvbs_log_err("cvbs_out_setmode:cvbsmode error.");
-       mutex_lock(&setmode_mutex);
        cvbs_log_info("SET cvbs mode:%s(%d)\n",
                (local_cvbs_mode == 0) ? "480cvbs" :
                ((local_cvbs_mode == 1) ? "576cvbs" :
                "invalid"), local_cvbs_mode);
+       if (local_cvbs_mode >= MODE_MAX) {
+               cvbs_log_err("cvbs_out_setmode:cvbsmode error.");
+               return -1;
+       }
+       mutex_lock(&setmode_mutex);
 
        cvbs_out_vpu_power_ctrl(1);
        cvbs_out_clk_gate_ctrl(1);
@@ -507,8 +509,7 @@ static const struct vinfo_s *get_valid_vinfo(char  *mode)
        for (i = 0; i < count; i++) {
                if (strncmp(cvbs_info[i].name, mode,
                            strlen(cvbs_info[i].name)) == 0) {
-                       if ((vinfo == NULL)
-                           || (strlen(cvbs_info[i].name) > mode_name_len)) {
+                       if (strlen(cvbs_info[i].name) > mode_name_len) {
                                vinfo = &cvbs_info[i];
                                mode_name_len = strlen(cvbs_info[i].name);
                                local_cvbs_mode = i;
@@ -517,7 +518,8 @@ static const struct vinfo_s *get_valid_vinfo(char  *mode)
                }
        }
        if (vinfo)
-               strcpy(vinfo->ext_name, mode);
+               strncpy(vinfo->ext_name, mode,
+               (strlen(mode) < 32) ? strlen(mode) : 31);
        else
                local_cvbs_mode = MODE_MAX;
        return vinfo;
@@ -1147,8 +1149,6 @@ static void cvbs_debug_store(char *buf)
                "\tclkdump\n"
                "\tset_clkpath 0/1/2/3\n");
                break;
-       default:
-               break;
        }
 
 DEBUG_END:
@@ -1201,7 +1201,6 @@ fail_create_device:
        cdev_del(info->cdev);
 fail_add_cdev:
        cvbs_log_info("[cvbs.] : cvbs add device error.\n");
-       kfree(info);
 fail_class_create_file:
        cvbs_log_info("[cvbs.] : cvbs class create file error.\n");
        for (i = 0; i < ARRAY_SIZE(cvbs_attr); i++)
index 65a48348eafc52eab11bec2edfcc1b1e829f9412..8876955cc8c50aabd0506ba5a46c5b44c5364e3f 100644 (file)
@@ -320,7 +320,7 @@ static void wss_process_cmd(unsigned int cmd, unsigned int param)
        else if (cmd == WSS_480I_CMD_OFF)
                wss_close_output(480);
        else {
-               if ((cmd >= WSS_576I_CMD_AR) && (cmd <= WSS_576I_CMD_OFF))
+               if (cmd <= WSS_576I_CMD_OFF)
                        mode = 576;
                else if ((cmd >= WSS_480I_CMD_AR) && (cmd <= WSS_480I_CMD_OFF))
                        mode = 480;
@@ -357,7 +357,7 @@ static void wss_show_status(unsigned int mode, char *wss_cmd)
 /* pr_info("[%s] mode = %d, wss_cmd = |%s|\n", __FUNCTION__, mode, wss_cmd); */
        if (mode == MODE_576CVBS) {
                if (!strncmp(wss_cmd, "cgms", strlen("cgms"))) {
-                       data = (data>>WSS_576I_CGMS_A_START) &
+                       data = (data >> WSS_576I_CGMS_A_START) &
                                                        WSS_576I_CGMS_A_MASK;
                        switch (data) {
                        case 0:
@@ -372,8 +372,6 @@ static void wss_show_status(unsigned int mode, char *wss_cmd)
                        case 3:
                                pr_info("cgms 3: copy right asserted / copying restricted\n");
                                break;
-                       default:
-                               break;
                        }
                }
        }
@@ -404,7 +402,7 @@ static void wss_dispatch_cmd(char *p)
                cmd = 0xee;
        else {
                if (get_local_cvbs_mode() == MODE_480CVBS) {
-                       cmd_max = sizeof(wss_480i_cmd);
+                       cmd_max = sizeof(wss_480i_cmd)/sizeof(char *);
                        for (i = 0; i < cmd_max; i++) {
                                if (!strncmp(argv[0], wss_480i_cmd[i],
                                                strlen(wss_480i_cmd[i]))) {
@@ -413,7 +411,7 @@ static void wss_dispatch_cmd(char *p)
                                }
                        }
                } else if (get_local_cvbs_mode() == MODE_576CVBS) {
-                       cmd_max = sizeof(wss_576i_cmd);
+                       cmd_max = sizeof(wss_576i_cmd)/sizeof(char *);
                        for (i = 0; i < cmd_max; i++) {
                                if (!strncmp(argv[0], wss_576i_cmd[i],
                                                strlen(wss_576i_cmd[i]))) {