net/sfc/base: refactoring eliminating code analysis warnings
authorRichard Houldsworth <rhouldsworth@solarflare.com>
Tue, 20 Feb 2018 07:33:45 +0000 (07:33 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 30 Mar 2018 12:08:42 +0000 (14:08 +0200)
Addresses most of the warnings reported by the sfn windows driver.

Signed-off-by: Richard Houldsworth <rhouldsworth@solarflare.com>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
drivers/net/sfc/base/ef10_mcdi.c
drivers/net/sfc/base/ef10_nvram.c
drivers/net/sfc/base/ef10_vpd.c
drivers/net/sfc/base/efx_filter.c
drivers/net/sfc/base/efx_mcdi.c
drivers/net/sfc/base/efx_phy.c
drivers/net/sfc/base/siena_mcdi.c
drivers/net/sfc/base/siena_nvram.c
drivers/net/sfc/base/siena_vpd.c

index b533033..8a3fc3b 100644 (file)
@@ -188,13 +188,17 @@ ef10_mcdi_read_response(
 {
        const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
        efsys_mem_t *esmp = emtp->emt_dma_mem;
-       unsigned int pos;
+       unsigned int pos = 0;
        efx_dword_t data;
+       size_t remaining = length;
+
+       while (remaining > 0) {
+               size_t chunk = MIN(remaining, sizeof (data));
 
-       for (pos = 0; pos < length; pos += sizeof (efx_dword_t)) {
                EFSYS_MEM_READD(esmp, offset + pos, &data);
-               memcpy((uint8_t *)bufferp + pos, &data,
-                   MIN(sizeof (data), length - pos));
+               memcpy((uint8_t *)bufferp + pos, &data, chunk);
+               pos += chunk;
+               remaining -= chunk;
        }
 }
 
index 6c670f2..2883ec8 100644 (file)
@@ -1349,12 +1349,16 @@ ef10_nvram_partn_read_tlv(
         */
        retry = 10;
        do {
-               rc = ef10_nvram_read_tlv_segment(enp, partn, 0,
-                   seg_data, partn_size);
-       } while ((rc == EAGAIN) && (--retry > 0));
+               if ((rc = ef10_nvram_read_tlv_segment(enp, partn, 0,
+                   seg_data, partn_size)) != 0)
+                       --retry;
+       } while ((rc == EAGAIN) && (retry > 0));
 
        if (rc != 0) {
                /* Failed to obtain consistent segment data */
+               if (rc == EAGAIN)
+                       rc = EIO;
+
                goto fail4;
        }
 
index f71bad3..097fe1d 100644 (file)
@@ -136,19 +136,22 @@ ef10_vpd_read(
                rc = ENOSPC;
                goto fail2;
        }
-       memcpy(data, dvpd, dvpd_size);
+       if (dvpd != NULL)
+               memcpy(data, dvpd, dvpd_size);
 
        /* Pad data with all-1s, consistent with update operations */
        memset(data + dvpd_size, 0xff, size - dvpd_size);
 
-       EFSYS_KMEM_FREE(enp->en_esip, dvpd_size, dvpd);
+       if (dvpd != NULL)
+               EFSYS_KMEM_FREE(enp->en_esip, dvpd_size, dvpd);
 
        return (0);
 
 fail2:
        EFSYS_PROBE(fail2);
 
-       EFSYS_KMEM_FREE(enp->en_esip, dvpd_size, dvpd);
+       if (dvpd != NULL)
+               EFSYS_KMEM_FREE(enp->en_esip, dvpd_size, dvpd);
 fail1:
        EFSYS_PROBE1(fail1, efx_rc_t, rc);
 
index e31accb..8705369 100644 (file)
@@ -959,6 +959,7 @@ siena_filter_build(
 
        default:
                EFSYS_ASSERT(B_FALSE);
+               EFX_ZERO_OWORD(*filter);
                return (0);
        }
 
index 254eb00..8156acc 100644 (file)
@@ -1432,6 +1432,10 @@ efx_mcdi_get_phy_cfg(
        efx_mcdi_req_t req;
        uint8_t payload[MAX(MC_CMD_GET_PHY_CFG_IN_LEN,
                            MC_CMD_GET_PHY_CFG_OUT_LEN)];
+#if EFSYS_OPT_NAMES
+       const char *namep;
+       size_t namelen;
+#endif
        efx_rc_t rc;
 
        (void) memset(payload, 0, sizeof (payload));
@@ -1455,10 +1459,12 @@ efx_mcdi_get_phy_cfg(
 
        encp->enc_phy_type = MCDI_OUT_DWORD(req, GET_PHY_CFG_OUT_TYPE);
 #if EFSYS_OPT_NAMES
-       (void) strncpy(encp->enc_phy_name,
-               MCDI_OUT2(req, char, GET_PHY_CFG_OUT_NAME),
-               MIN(sizeof (encp->enc_phy_name) - 1,
-                   MC_CMD_GET_PHY_CFG_OUT_NAME_LEN));
+       namep = MCDI_OUT2(req, char, GET_PHY_CFG_OUT_NAME);
+       namelen = MIN(sizeof (encp->enc_phy_name) - 1,
+                   strnlen(namep, MC_CMD_GET_PHY_CFG_OUT_NAME_LEN));
+       (void) memset(encp->enc_phy_name, 0,
+           sizeof (encp->enc_phy_name));
+       memcpy(encp->enc_phy_name, namep, namelen);
 #endif /* EFSYS_OPT_NAMES */
        (void) memset(encp->enc_phy_revision, 0,
            sizeof (encp->enc_phy_revision));
index 2598928..ba2f51c 100644 (file)
@@ -185,6 +185,7 @@ efx_phy_adv_cap_get(
                break;
        default:
                EFSYS_ASSERT(B_FALSE);
+               *maskp = 0;
                break;
        }
 }
index ef84459..d727c18 100644 (file)
@@ -124,17 +124,21 @@ siena_mcdi_read_response(
 {
        efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
        unsigned int pdur;
-       unsigned int pos;
+       unsigned int pos = 0;
        efx_dword_t data;
+       size_t remaining = length;
 
        EFSYS_ASSERT(emip->emi_port == 1 || emip->emi_port == 2);
        pdur = SIENA_MCDI_PDU(emip);
 
-       for (pos = 0; pos < length; pos += sizeof (efx_dword_t)) {
+       while (remaining > 0) {
+               size_t chunk = MIN(remaining, sizeof (data));
+
                EFX_BAR_TBL_READD(enp, FR_CZ_MC_TREG_SMEM,
                    pdur + ((offset + pos) >> 2), &data, B_FALSE);
-               memcpy((uint8_t *)bufferp + pos, &data,
-                   MIN(sizeof (data), length - pos));
+               memcpy((uint8_t *)bufferp + pos, &data, chunk);
+               pos += chunk;
+               remaining -= chunk;
        }
 }
 
index e72bba0..8cdd2df 100644 (file)
@@ -304,15 +304,20 @@ siena_nvram_get_dynamic_cfg(
        if ((rc = siena_nvram_partn_size(enp, partn, &size)) != 0)
                goto fail1;
 
+       if (size < SIENA_NVRAM_CHUNK) {
+               rc = EINVAL;
+               goto fail2;
+       }
+
        EFSYS_KMEM_ALLOC(enp->en_esip, size, dcfg);
        if (dcfg == NULL) {
                rc = ENOMEM;
-               goto fail2;
+               goto fail3;
        }
 
        if ((rc = siena_nvram_partn_read(enp, partn, 0,
            (caddr_t)dcfg, SIENA_NVRAM_CHUNK)) != 0)
-               goto fail3;
+               goto fail4;
 
        /* Verify the magic */
        if (EFX_DWORD_FIELD(dcfg->magic, EFX_DWORD_0)
@@ -347,7 +352,7 @@ siena_nvram_get_dynamic_cfg(
                if ((rc = siena_nvram_partn_read(enp, partn, SIENA_NVRAM_CHUNK,
                    (caddr_t)dcfg + SIENA_NVRAM_CHUNK,
                    region - SIENA_NVRAM_CHUNK)) != 0)
-                       goto fail4;
+                       goto fail5;
        }
 
        /* Verify checksum */
@@ -389,13 +394,15 @@ done:
 
        return (0);
 
+fail5:
+       EFSYS_PROBE(fail5);
 fail4:
        EFSYS_PROBE(fail4);
-fail3:
-       EFSYS_PROBE(fail3);
 
        EFSYS_KMEM_FREE(enp->en_esip, size, dcfg);
 
+fail3:
+       EFSYS_PROBE(fail3);
 fail2:
        EFSYS_PROBE(fail2);
 fail1:
index f188eb5..ebb12ab 100644 (file)
@@ -36,21 +36,26 @@ siena_vpd_get_static(
        if ((rc = siena_nvram_partn_size(enp, partn, &size)) != 0)
                goto fail1;
 
+       if (size < SIENA_NVRAM_CHUNK) {
+               rc = EINVAL;
+               goto fail2;
+       }
+
        EFSYS_KMEM_ALLOC(enp->en_esip, size, scfg);
        if (scfg == NULL) {
                rc = ENOMEM;
-               goto fail2;
+               goto fail3;
        }
 
        if ((rc = siena_nvram_partn_read(enp, partn, 0,
            (caddr_t)scfg, SIENA_NVRAM_CHUNK)) != 0)
-               goto fail3;
+               goto fail4;
 
        /* Verify the magic number */
        if (EFX_DWORD_FIELD(scfg->magic, EFX_DWORD_0) !=
            SIENA_MC_STATIC_CONFIG_MAGIC) {
                rc = EINVAL;
-               goto fail4;
+               goto fail5;
        }
 
        /* All future versions of the structure must be backwards compatible */
@@ -64,7 +69,7 @@ siena_vpd_get_static(
        if (hdr_length > size || vpd_offset > size || vpd_length > size ||
            vpd_length + vpd_offset > size) {
                rc = EINVAL;
-               goto fail5;
+               goto fail6;
        }
 
        /* Read the remainder of scfg + static vpd */
@@ -73,7 +78,7 @@ siena_vpd_get_static(
                if ((rc = siena_nvram_partn_read(enp, partn, SIENA_NVRAM_CHUNK,
                    (caddr_t)scfg + SIENA_NVRAM_CHUNK,
                    region - SIENA_NVRAM_CHUNK)) != 0)
-                       goto fail6;
+                       goto fail7;
        }
 
        /* Verify checksum */
@@ -82,7 +87,7 @@ siena_vpd_get_static(
                cksum += ((uint8_t *)scfg)[pos];
        if (cksum != 0) {
                rc = EINVAL;
-               goto fail7;
+               goto fail8;
        }
 
        if (vpd_length == 0)
@@ -92,7 +97,7 @@ siena_vpd_get_static(
                EFSYS_KMEM_ALLOC(enp->en_esip, vpd_length, svpd);
                if (svpd == NULL) {
                        rc = ENOMEM;
-                       goto fail8;
+                       goto fail9;
                }
                memcpy(svpd, (caddr_t)scfg + vpd_offset, vpd_length);
        }
@@ -104,6 +109,8 @@ siena_vpd_get_static(
 
        return (0);
 
+fail9:
+       EFSYS_PROBE(fail9);
 fail8:
        EFSYS_PROBE(fail8);
 fail7:
@@ -114,11 +121,11 @@ fail5:
        EFSYS_PROBE(fail5);
 fail4:
        EFSYS_PROBE(fail4);
-fail3:
-       EFSYS_PROBE(fail3);
 
        EFSYS_KMEM_FREE(enp->en_esip, size, scfg);
 
+fail3:
+       EFSYS_PROBE(fail3);
 fail2:
        EFSYS_PROBE(fail2);
 fail1: