tvin: coverity fix
authorxuhua zhang <xuhua.zhang@amlogic.com>
Wed, 20 Jun 2018 03:35:24 +0000 (11:35 +0800)
committerYixun Lan <yixun.lan@amlogic.com>
Thu, 21 Jun 2018 07:29:18 +0000 (00:29 -0700)
PD#168718: tvin: coverity fix

Change-Id: I196de9ae44fc443f5cb7050fad92bea9cd138c8a
Signed-off-by: xuhua zhang <xuhua.zhang@amlogic.com>
13 files changed:
drivers/amlogic/media/vin/tvin/hdmirx_ext/hdmirx_ext_attrs.c
drivers/amlogic/media/vin/tvin/hdmirx_ext/hdmirx_ext_hw_iface.c
drivers/amlogic/media/vin/tvin/hdmirx_ext/hw_sii9135/SiIInfoPkts.c
drivers/amlogic/media/vin/tvin/hdmirx_ext/hw_sii9135/UCfgRX.c
drivers/amlogic/media/vin/tvin/hdmirx_ext/hw_sii9135/UEEPROM.c
drivers/amlogic/media/vin/tvin/tvafe/tvafe_avin_detect.c
drivers/amlogic/media/vin/tvin/tvafe/tvafe_cvd.c
drivers/amlogic/media/vin/tvin/tvafe/tvafe_debug.c
drivers/amlogic/media/vin/tvin/tvafe/tvafe_vbi.c
drivers/amlogic/media/vin/tvin/vdin/vdin_ctl.c
drivers/amlogic/media/vin/tvin/vdin/vdin_debug.c
drivers/amlogic/media/vin/tvin/vdin/vdin_drv.c
drivers/amlogic/media/vin/tvin/vdin/vdin_vf.c

index f81b9896767b4a150e152dca8b56a8ba9e908efc..bf2db5fbe93a98ff24eb0eff768cd4aae9950ac7 100644 (file)
@@ -219,10 +219,14 @@ static ssize_t hdmirx_ext_video_mode_show(struct device *dev,
 
        mode_str = __plat_get_video_mode_name(mode);
 
-       if (strcmp(mode_str, "invalid") != 0)
-               strcat(hdmi_mode_str, mode_str);
-       else
-               strcpy(hdmi_mode_str, mode_str);
+       if (strcmp(mode_str, "invalid") != 0) {
+               if (strlen(mode_str) <
+                       (sizeof(hdmi_mode_str) - strlen(hdmi_mode_str)))
+                       strcat(hdmi_mode_str, mode_str);
+       } else {
+               if (strlen(mode_str) < sizeof(hdmi_mode_str))
+                       strcpy(hdmi_mode_str, mode_str);
+       }
        return sprintf(buf, "%s\n", hdmi_mode_str);
 }
 
@@ -268,7 +272,8 @@ static ssize_t hdmirx_ext_audio_sr_show(struct device *dev,
        };
 
        audio_sr = __hw_get_audio_sample_rate();
-       if ((audio_sr < 0) || (audio_sr > sizeof(audio_sr_array)))
+       if ((audio_sr < 0) ||
+               (audio_sr >= (sizeof(audio_sr_array)/sizeof(char *))))
                audio_sr = 0;
 
        return sprintf(buf, "%s\n", audio_sr_array[audio_sr]);
index 494ea143e5659b3c092c6d5989e2d0a90e7cb97b..d91470a1ab074b8d4b1e04b3ec3fc6b9835c07b3 100644 (file)
@@ -193,7 +193,10 @@ int __hw_enable(void)
 {
        struct hdmirx_ext_drv_s *hdrv = hdmirx_ext_get_driver();
 
-       if ((hdrv) && (hdrv->hw.enable))
+       if (!hdrv)
+               return -1;
+
+       if (hdrv->hw.enable)
                return hdrv->hw.enable();
        hdrv->state = 1;
 
@@ -206,8 +209,12 @@ void __hw_disable(void)
 {
        struct hdmirx_ext_drv_s *hdrv = hdmirx_ext_get_driver();
 
+       if (!hdrv)
+               return;
+
        hdrv->state = 0;
-       if ((hdrv) && (hdrv->hw.disable))
+
+       if (hdrv->hw.disable)
                hdrv->hw.disable();
 }
 
index 6d8e9df2106735c1bd2d91f9127d01d92be48698..5f68556975b87185e6ecc161bf1b2b090acc12a3 100644 (file)
@@ -276,17 +276,17 @@ static void SetAVI_Info(struct AVIType_s *AVI, BYTE *Data)
        bAVI = Data[IF_HEADER_LENGTH] & ColorSpaceMask;
        if (bAVI == RGB)
                AVI->bInputColorSpace = SiI_RX_ICP_RGB;
-       else if (bAVI == YCbCr422)
+       else if (bAVI == (BYTE)YCbCr422)
                AVI->bInputColorSpace = SiI_RX_ICP_YCbCr422;
-       else if (bAVI == YCbCr444)
+       else if (bAVI == (BYTE)YCbCr444)
                AVI->bInputColorSpace = SiI_RX_ICP_YCbCr444;
 
        bAVI = Data[IF_HEADER_LENGTH + 1] & ColorimetryMask;
        if (bAVI == NoInfo)
                AVI->bColorimetry = SiI_RX_ColorimetryNoInfo;
-       else if (bAVI == ITU601)
+       else if (bAVI == (BYTE)ITU601)
                AVI->bColorimetry = SiI_RX_ITU_601;
-       else if (bAVI == ITU709)
+       else if (bAVI == (BYTE)ITU709)
                AVI->bColorimetry = SiI_RX_ITU_709;
 
        AVI->bPixRepl = Data[IF_HEADER_LENGTH + 4] & PixReplicationMask;
index a374b5b61b6d6848dae4ece3d3cfdb10e88661d3..ed22138dfaf427237c8ce361e4b093942846a278 100644 (file)
@@ -51,7 +51,7 @@ BYTE siiGetPCB_Id(void)
  */
 void InitEEPROMWithDefaults(void)
 {
-       BYTE abData[6];
+       BYTE abData[7];
 
        abData[0] = RX_API_ID_L;
        abData[1] = RX_API_ID_H;
@@ -182,7 +182,7 @@ static void PrintIntilizeSystemWith(BYTE *pbInitData)
  */
 static BYTE siiRXAPIConfig(void)
 {
-       BYTE abData[6];
+       BYTE abData[8];
        BYTE bError;
        WORD wDevId;
 
index 97b68a1ce080bffb85bc0a1ccde723594b802306..cfbd42b253a9c9319811eb066ce6cf5de4151b5a 100644 (file)
@@ -94,7 +94,7 @@ void siiBlockWriteEEPROM(WORD Addr, BYTE NBytes, BYTE *Data)
        hlBlockWrite_8BAS((struct I2CShortCommandType_s *)&I2CComm, Data);
 #endif
 
-       hlWaitForAck(bEEPROMSlaveAddr, 100);
+       /*hlWaitForAck(bEEPROMSlaveAddr, 100);*/
 }
 /*----------------------------------------------------------------------*/
 
index f36a177ddc95a2119a64f3c79172ab47b2270b82..ebca5bacb8759c02e28332f21eda656de8d23a7f 100644 (file)
@@ -449,7 +449,7 @@ static void tvafe_avin_detect_state(struct tvafe_avin_det_s *avdev)
 static void tvafe_avin_detect_parse_param(char *buf_orig, char **parm)
 {
        char *ps, *token;
-       char delim1[2] = " ";
+       char delim1[3] = " ";
        char delim2[2] = "\n";
        unsigned int n = 0;
 
index ceea121a25347a1bd182809a2d3d264e50595f67..2421a5476d9d65b9d7b69203dbacacbe40e547d4 100644 (file)
@@ -392,7 +392,7 @@ static void tvafe_cvd2_write_mode_reg(struct tvafe_cvd2_s *cvd2,
                }
 
 
-       } else{
+       } else {
 
                for (i = 0; i < (ACD_REG_NUM+1); i++) {
 
@@ -462,7 +462,7 @@ static void tvafe_cvd2_write_mode_reg(struct tvafe_cvd2_s *cvd2,
                        ADAPTIVE_CHROMA_MODE_BIT, ADAPTIVE_CHROMA_MODE_WID);
                W_APB_BIT(CVD2_CONTROL1, 0, CHROMA_BW_LO_BIT, CHROMA_BW_LO_WID);
 
-       } else{
+       } else {
                W_APB_REG(CVD2_VSYNC_NO_SIGNAL_THRESHOLD, 0xf0);
                if (cvd2->config_fmt == TVIN_SIG_FMT_CVBS_PAL_I)
                                /*add for chroma state adjust dynamicly*/
@@ -642,7 +642,7 @@ static void tvafe_cvd2_non_std_config(struct tvafe_cvd2_s *cvd2)
                        /* vsync signal is not good */
                        W_APB_REG(CVD2_NOISE_THRESHOLD, 0x00);
 
-               } else{
+               } else {
 
                        if (scene_colorful)
                                W_APB_REG(CVD2_VSYNC_CNTL, 0x02);
@@ -654,7 +654,7 @@ static void tvafe_cvd2_non_std_config(struct tvafe_cvd2_s *cvd2)
                }
 #endif
 
-       } else{
+       } else {
                if (cvd_nonstd_dbg_en)
                        tvafe_pr_info("%s: out of non-std signal.\n",
                                __func__);
@@ -700,7 +700,7 @@ static void tvafe_cvd2_non_std_config(struct tvafe_cvd2_s *cvd2)
                        W_APB_BIT(CVD2_ACTIVE_VIDEO_VHEIGHT, 0xc0,
                                        VACTIVE_HEIGHT_BIT, VACTIVE_HEIGHT_WID);
 
-               } else{
+               } else {
 
                        W_APB_BIT(CVD2_VSYNC_SIGNAL_THRESHOLD, 0,
                                VS_SIGNAL_AUTO_TH_BIT, VS_SIGNAL_AUTO_TH_WID);
@@ -1226,7 +1226,7 @@ static void tvafe_cvd2_non_std_signal_det(
 
                        cvd2->info.non_std_enable = 1;
 
-               } else{
+               } else {
 
                        cvd2->info.non_std_enable = 0;
                }
@@ -1248,7 +1248,7 @@ static bool tvafe_cvd2_sig_unstable(struct tvafe_cvd2_s *cvd2)
                if (cvd2->hw.no_sig)/* || !cvd2->hw.h_lock) */
                        ret = true;
 
-       } else{
+       } else {
 
                if (cvd2->hw.no_sig || !cvd2->hw.h_lock || !cvd2->hw.v_lock)
                        ret = true;
@@ -1381,7 +1381,7 @@ static bool tvafe_cvd2_condition_shift(struct tvafe_cvd2_s *cvd2)
                                        __func__);
                        }
 
-               } else{
+               } else {
 
                        if (R_APB_BIT(CVD2_CHROMA_DTO_INCREMENT_23_16,
                                CDTO_INC_23_16_BIT, CDTO_INC_23_16_WID) !=
@@ -1738,7 +1738,7 @@ static void tvafe_cvd2_search_video_mode(struct tvafe_cvd2_s *cvd2,
                                /* line525 + 358 =>*/
                                /*confirm NTSC_M */
                                cvd2->info.state = TVAFE_CVD2_STATE_FIND;
-                       } else{
+                       } else {
                                if (cvd_dbg_en)
                                        tvafe_pr_info("%s dismatch ntsc m line625 %d, fsc358 %d,pal %d",
                                        __func__, cvd2->hw.line625,
@@ -2017,7 +2017,7 @@ inline bool tvafe_cvd2_no_sig(struct tvafe_cvd2_s *cvd2,
                ret = true;
                tvafe_cvd2_reinit(cvd2);
 
-       } else{
+       } else {
                ret = false;
                cvd2->cvd2_init_en = false;
 #ifdef TVAFE_CVD2_AUTO_DE_ENABLE
@@ -2135,7 +2135,7 @@ inline void tvafe_cvd2_adj_pga(struct tvafe_cvd2_s *cvd2)
                        pga += step;
                        if (pga >= 255)  /* set max value */
                                pga = 255;
-               } else{
+               } else {
                        if (pga < step)  /* set min value */
                                pga = 0;
                        else
index 5d296329685678393995265cbefeeb8231d5a8a1..0626b691074e24e75f00c7832eb78d62f0e28112 100644 (file)
@@ -178,7 +178,7 @@ static void tvafe_state(struct tvafe_dev_s *devp)
 static void tvafe_parse_param(char *buf_orig, char **parm)
 {
        char *ps, *token;
-       char delim1[2] = " ";
+       char delim1[3] = " ";
        char delim2[2] = "\n";
        unsigned int n = 0;
 
@@ -355,7 +355,7 @@ static ssize_t tvafe_dumpmem_store(struct device *dev,
        char *buf_orig, *ps, *token;
        char *parm[6] = {NULL};
        struct tvafe_dev_s *devp;
-       char delim1[2] = " ";
+       char delim1[3] = " ";
        char delim2[2] = "\n";
 
        strcat(delim1, delim2);
@@ -372,7 +372,7 @@ static ssize_t tvafe_dumpmem_store(struct device *dev,
                if (*token == '\0')
                        continue;
                parm[n++] = token;
-               }
+       }
        if (!strncmp(parm[0], "dumpmem", strlen("dumpmem"))) {
                if (parm[1] != NULL) {
                        struct file *filp = NULL;
index b8edaf035e564ed19372d0776b2b71f3544f5ea4..21a3ee5df45b2292bc189adbe8ebe30da21b49f4 100644 (file)
@@ -348,7 +348,8 @@ static int vbi_buffer_write(struct vbi_ringbuffer_s *buf,
                        tvafe_pr_info("%s: buffer len is zero\n", __func__);
                return 0;
        }
-       if (!buf->data) {
+
+       if ((buf == NULL) || (buf->data == NULL)) {
                if (capture_print_en)
                        tvafe_pr_info("%s: buffer data pointer is zero\n",
                        __func__);
@@ -465,9 +466,6 @@ unsigned char *search_table(unsigned char *table_start_addr,
                tvafe_pr_info("search_table add err: start=%p,search=%p,end=%p\n",
                        table_start_addr, search_point, table_end_addr);
                return NULL;
-       } else if (search_size > VBI_BUFF2_SIZE) {
-               tvafe_pr_info("search_size out of range\n");
-               return NULL;
        }
 
        while (count++ < table_size) {
@@ -834,7 +832,7 @@ void vbi_ringbuffer_reset(struct vbi_ringbuffer_s *rbuf)
 }
 
 static int vbi_set_buffer_size(struct vbi_dev_s *dev,
-                     unsigned long size)
+                     unsigned int size)
 {
        struct vbi_slicer_s *vbi_slicer = dev->slicer;
        struct vbi_ringbuffer_s *buf = &vbi_slicer->buffer;
@@ -960,7 +958,7 @@ static ssize_t vbi_buffer_read(struct vbi_ringbuffer_s *src,
        ssize_t ret = 0;
        ssize_t timeout = 0;
 
-       if (!src->data) {
+       if ((src == NULL) || (src->data == NULL)) {
                tvafe_pr_info("%s: data null\n", __func__);
                return 0;
        }
@@ -1102,7 +1100,7 @@ static long vbi_ioctl(struct file *file,
 {
        int ret = 0;
        void __user *argp = (void __user *)arg;
-       unsigned long buffer_size_t;
+       unsigned int buffer_size_t;
 
        struct vbi_dev_s *vbi_dev = file->private_data;
        struct vbi_slicer_s *vbi_slicer = vbi_dev->slicer;
@@ -1282,7 +1280,7 @@ static struct resource vbi_memobj;
 static void vbi_parse_param(char *buf_orig, char **parm)
 {
        char *ps, *token;
-       char delim1[2] = " ";
+       char delim1[3] = " ";
        char delim2[2] = "\n";
        unsigned int n = 0;
 
@@ -1378,13 +1376,17 @@ static ssize_t vbi_store(struct device *dev,
        char *buf_orig;
        char *parm[6] = {NULL};
        struct vbi_dev_s *devp = dev_get_drvdata(dev);
-       struct vbi_slicer_s *vbi_slicer = devp->slicer;
-       struct vbi_ringbuffer_s *vbi_buffer = &(vbi_slicer->buffer);
+       struct vbi_slicer_s *vbi_slicer;
+       struct vbi_ringbuffer_s *vbi_buffer;
        long val;
        int ret = 0;
 
        if (!buff || !devp)
                return len;
+
+       vbi_slicer = devp->slicer;
+       vbi_buffer = &(vbi_slicer->buffer);
+
        buf_orig = kstrdup(buff, GFP_KERNEL);
        vbi_parse_param(buf_orig, (char **)&parm);
        if (!strncmp(parm[0], "dumpmem", strlen("dumpmem"))) {
@@ -1450,7 +1452,7 @@ static ssize_t vbi_store(struct device *dev,
        } else if (!strncmp(parm[0], "set_size", strlen("set_size"))) {
                if (kstrtol(parm[1], 10, &val) < 0)
                        return -EINVAL;
-               vbi_set_buffer_size(devp, val);
+               vbi_set_buffer_size(devp, (unsigned int)val);
                tvafe_pr_info(" set buf size to %d\n",
                        vbi_slicer->buffer.size);
        } else if (!strncmp(parm[0], "set_type", strlen("set_type"))) {
index 55ca28b930f3bea8657f0574acadbc8ffd3b59e2..fcf893193b7f6d45ec7868050403cfa8936d9c33 100644 (file)
@@ -3776,7 +3776,7 @@ int vdin_event_cb(int type, void *data, void *op_arg)
                req->low_latency = 0;
                if (req->bot_flag)
                        index = (req->vf->index >> 8) & 0xff;
-               if (index != 0xff && index >= 0
+               if (index != 0xff
                        && index < p->size
                        && p->dv_buf[index]) {
                        req->aux_buf = p->dv_buf[index];
index d7b9534eb6b5a81e145fc6bd1ff1ded3d0242594..d0d5a880fdc79087b7c28cf6a292484e4b11a61f 100644 (file)
@@ -76,7 +76,7 @@ static void vdin_set_before_after_mat0(unsigned int offset,
 static void vdin_parse_param(char *buf_orig, char **parm)
 {
        char *ps, *token;
-       char delim1[2] = " ";
+       char delim1[3] = " ";
        char delim2[2] = "\n";
        unsigned int n = 0;
        ps = buf_orig;
@@ -1673,7 +1673,7 @@ static ssize_t vdin_cm2_store(struct device *dev,
        unsigned int addr_port = VDIN_CHROMA_ADDR_PORT;
        unsigned int data_port = VDIN_CHROMA_DATA_PORT;
        long val;
-       char delim1[2] = " ";
+       char delim1[3] = " ";
        char delim2[2] = "\n";
 
        strcat(delim1, delim2);
index 76814b7343969d968fec0c0b119a324ed6af1455..99713609be957d40ce9aa38260976c511637fb5f 100644 (file)
@@ -1160,7 +1160,7 @@ irqreturn_t vdin_isr(int irq, void *dev_id)
        unsigned int stamp = 0;
        struct tvin_state_machine_ops_s *sm_ops;
        int vdin2nr = 0;
-       unsigned int offset, vf_drop_cnt;
+       unsigned int offset = 0, vf_drop_cnt = 0;
        enum tvin_trans_fmt trans_fmt;
        struct tvin_sig_property_s *prop, *pre_prop;
 
@@ -1170,6 +1170,15 @@ irqreturn_t vdin_isr(int irq, void *dev_id)
         * because the spinlock may affect the system time.
         */
 
+       /* avoid null pointer oops */
+       if (!devp)
+               return IRQ_HANDLED;
+
+       if (!devp->frontend) {
+               devp->vdin_irq_flag = 1;
+               goto irq_handled;
+       }
+
        /* ignore fake irq caused by sw reset*/
        if (devp->vdin_reset_flag) {
                devp->vdin_reset_flag = 0;
@@ -1177,11 +1186,6 @@ irqreturn_t vdin_isr(int irq, void *dev_id)
        }
        vf_drop_cnt = vdin_drop_cnt;
 
-       /* avoid null pointer oops */
-       if (!devp || !devp->frontend) {
-               devp->vdin_irq_flag = 1;
-               goto irq_handled;
-       }
        offset = devp->addr_offset;
 
        isr_log(devp->vfp);
@@ -1840,7 +1844,7 @@ static int vdin_release(struct inode *inode, struct file *file)
 static long vdin_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        long ret = 0;
-       int callmaster_status;
+       int callmaster_status = 0;
        struct vdin_dev_s *devp = NULL;
        void __user *argp = (void __user *)arg;
 
index 5a245157b979017fba01ef4365793acee8727e9b..7b9d5112b14dba7e1c767358d8e9206e4777732a 100644 (file)
@@ -956,7 +956,7 @@ void vdin_vf_disp_mode_update(struct vf_entry *vfe, struct vf_pool *p)
        vfe->vf.index_disp = p->disp_index[0];
 
        p->disp_mode[p->disp_index[p->skip_vf_num]] = VFRAME_DISP_MODE_OK;
-       for (i = p->skip_vf_num - 1; (i >= 0) && (i < VFRAME_DISP_MAX_NUM); i--)
+       for (i = p->skip_vf_num - 1; i < VFRAME_DISP_MAX_NUM; i--)
                p->disp_mode[p->disp_index[i]] = VFRAME_DISP_MODE_UNKNOWN;
 }
 /*disp mode skip
@@ -968,7 +968,7 @@ void vdin_vf_disp_mode_skip(struct vf_pool *p)
 {
        unsigned int i;
 
-       for (i = p->skip_vf_num - 1; (i >= 0) && (i < VFRAME_DISP_MAX_NUM); i--)
+       for (i = p->skip_vf_num - 1; i < VFRAME_DISP_MAX_NUM; i--)
                p->disp_mode[i] = VFRAME_DISP_MODE_SKIP;
 }