net/nfp: check return value
authorAlejandro Lucero <alejandro.lucero@netronome.com>
Mon, 8 Apr 2019 09:59:49 +0000 (10:59 +0100)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 12 Apr 2019 09:02:02 +0000 (11:02 +0200)
Call to CPP read (nfp_cpp_readl()) can fail, return 0 on fail.

If the call to _nfp6000_cppat_mu_locality fails, the function needs
to return with an error.

If the nfp_cpp_readl() call fails just returns 0.

Coverity issue: 277209, 277215, 277225
Fixes: c7e9729da6b5 ("net/nfp: support CPP")
Cc: stable@dpdk.org
Signed-off-by: Alejandro Lucero <alejandro.lucero@netronome.com>
drivers/net/nfp/nfpcore/nfp-common/nfp_cppat.h
drivers/net/nfp/nfpcore/nfp_cppcore.c

index 6e380cc..538f882 100644 (file)
@@ -368,6 +368,9 @@ _nfp6000_encode_mu(uint64_t *addr, int dest_island, int mode, int addr40,
        isld[1] = isld1;
        locality_lsb = _nfp6000_cppat_mu_locality_lsb(mode, addr40);
 
+       if (locality_lsb < 0)
+               return NFP_ERRNO(EINVAL);
+
        if (((*addr >> locality_lsb) & 3) == _NIC_NFP6000_MU_LOCALITY_DIRECT)
                da = 1;
        else
index 75d3c97..dec4a8b 100644 (file)
@@ -801,7 +801,8 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp)
        uint32_t arm_id = NFP_CPP_ID(NFP_CPP_TARGET_ARM, 0, 0);
        uint32_t model = 0;
 
-       nfp_cpp_readl(cpp, arm_id, NFP6000_ARM_GCSR_SOFTMODEL0, &model);
+       if (nfp_cpp_readl(cpp, arm_id, NFP6000_ARM_GCSR_SOFTMODEL0, &model))
+               return 0;
 
        if (NFP_CPP_MODEL_IS_6000(model)) {
                uint32_t tmp;
@@ -810,8 +811,10 @@ __nfp_cpp_model_autodetect(struct nfp_cpp *cpp)
 
                /* The PL's PluDeviceID revision code is authoratative */
                model &= ~0xff;
-               nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) +
-                                  NFP_PL_DEVICE_ID, &tmp);
+               if (nfp_xpb_readl(cpp, NFP_XPB_DEVICE(1, 1, 16) +
+                                  NFP_PL_DEVICE_ID, &tmp))
+                       return 0;
+
                model |= (NFP_PL_DEVICE_ID_MASK & tmp) - 0x10;
        }