hdmitx: Coverity(upgraded) defect cleanup: hdmitx [1/1]
authorZhengrong.Zhu <zhengrong.zhu@amlogic.com>
Fri, 22 Nov 2019 11:16:30 +0000 (19:16 +0800)
committerTao Zeng <tao.zeng@amlogic.com>
Wed, 4 Dec 2019 01:17:03 +0000 (18:17 -0700)
PD#SWPL-16574

Problem:
Coverity(upgraded) defect cleanup: hdmitx

Solution:
Modify code according to coverity

Verify:
verify on the board of U212

Change-Id: Iac69fb896dd22b38ae56b58701d6fd26aefe958c
Signed-off-by: Zhengrong Zhu <zhengrong.zhu@amlogic.com>
(cherry picked from commit cbbac9335c19d09c6bf50e6069d79f973129210a)

drivers/amlogic/media/vout/hdmitx/hdmi_tx_20/hdmi_tx_edid.c
drivers/amlogic/media/vout/hdmitx/hdmi_tx_20/hdmi_tx_main.c

index 0421dadd94f6398b5ed01f1978cbcc58a1e9953d..cbc50b82e3755a89a933c0fe37f756d69b1f4e16 100644 (file)
@@ -1855,7 +1855,7 @@ static int hdmitx_edid_search_IEEEOUI(char *buf)
 {
        int i;
 
-       for (i = 0; i < 0x180; i++) {
+       for (i = 0; i < 0x180 - 2; i++) {
                if ((buf[i] == 0x03) && (buf[i+1] == 0x0c) &&
                        (buf[i+2] == 0x00))
                        return 1;
index ac4bb81a5af7ff51c9682234b87bd0d16675e61d..a612a27acf862b6c69d03ea8577ecf6a59ad2018 100644 (file)
@@ -4559,18 +4559,19 @@ static void hdmitx_fmt_attr(struct hdmitx_dev *hdev)
            (hdev->para->cs == COLORSPACE_RESERVED)) {
                strcpy(hdev->fmt_attr, "default");
        } else {
+               memset(hdev->fmt_attr, 0, sizeof(hdev->fmt_attr));
                switch (hdev->para->cs) {
                case COLORSPACE_RGB444:
-                       memcpy(hdev->fmt_attr, "rgb,", 4);
+                       memcpy(hdev->fmt_attr, "rgb,", 5);
                        break;
                case COLORSPACE_YUV422:
-                       memcpy(hdev->fmt_attr, "422,", 4);
+                       memcpy(hdev->fmt_attr, "422,", 5);
                        break;
                case COLORSPACE_YUV444:
-                       memcpy(hdev->fmt_attr, "444,", 4);
+                       memcpy(hdev->fmt_attr, "444,", 5);
                        break;
                case COLORSPACE_YUV420:
-                       memcpy(hdev->fmt_attr, "420,", 4);
+                       memcpy(hdev->fmt_attr, "420,", 5);
                        break;
                default:
                        break;
@@ -5409,8 +5410,10 @@ static void check_hdmiuboot_attr(char *token)
        }
        for (i = 0; cd[i] != NULL; i++) {
                if (strstr(token, cd[i])) {
-                       if (strlen(cd[i]) < (sizeof(attr) - strlen(attr)))
-                               strncat(attr, cd[i], strlen(cd[i]));
+                       if (strlen(cd[i]) < sizeof(attr))
+                               if (strlen(cd[i]) <
+                                       (sizeof(attr) - strlen(attr)))
+                                       strncat(attr, cd[i], strlen(cd[i]));
                        strncpy(hdmitx_device.fmt_attr, attr,
                                sizeof(hdmitx_device.fmt_attr));
                        hdmitx_device.fmt_attr[15] = '\0';