[dpdk-dev,52/53] net/sfc/base: fix PreFAST static analysis warning (C6001)

Message ID 1510819481-6809-53-git-send-email-arybchenko@solarflare.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Andrew Rybchenko Nov. 16, 2017, 8:04 a.m. UTC
  From: Andrew Lee <alee@solarflare.com>

Fix warning
"C6001: Using uninitialized memory '*sensor_maskp'"
which could occur when the npages argument to efx_mcdi_sensor_info()
is less than or equal to zero.

Fixes: dfb3b1ce15f6 ("net/sfc/base: import monitors access via MCDI")
Cc: stable@dpdk.org

Signed-off-by: Andrew Lee <alee@solarflare.com>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
---
 drivers/net/sfc/base/mcdi_mon.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
  

Patch

diff --git a/drivers/net/sfc/base/mcdi_mon.c b/drivers/net/sfc/base/mcdi_mon.c
index 8ea4216..7e4264a 100644
--- a/drivers/net/sfc/base/mcdi_mon.c
+++ b/drivers/net/sfc/base/mcdi_mon.c
@@ -396,6 +396,11 @@  efx_mcdi_sensor_info(
 
 	EFSYS_ASSERT(sensor_maskp != NULL);
 
+	if (npages < 1) {
+		rc = EINVAL;
+		goto fail1;
+	}
+
 	for (page = 0; page < npages; page++) {
 		uint32_t mask;
 
@@ -412,7 +417,7 @@  efx_mcdi_sensor_info(
 
 		if (req.emr_rc != 0) {
 			rc = req.emr_rc;
-			goto fail1;
+			goto fail2;
 		}
 
 		mask = MCDI_OUT_DWORD(req, SENSOR_INFO_OUT_MASK);
@@ -420,18 +425,20 @@  efx_mcdi_sensor_info(
 		if ((page != (npages - 1)) &&
 		    ((mask & (1U << MC_CMD_SENSOR_PAGE0_NEXT)) == 0)) {
 			rc = EINVAL;
-			goto fail2;
+			goto fail3;
 		}
 		sensor_maskp[page] = mask;
 	}
 
 	if (sensor_maskp[npages - 1] & (1U << MC_CMD_SENSOR_PAGE0_NEXT)) {
 		rc = EINVAL;
-		goto fail3;
+		goto fail4;
 	}
 
 	return (0);
 
+fail4:
+	EFSYS_PROBE(fail4);
 fail3:
 	EFSYS_PROBE(fail3);
 fail2: