[v1] net/ice: fix dereference before null check

Message ID 20220207082558.1349140-1-stevex.yang@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Qi Zhang
Headers
Series [v1] net/ice: fix dereference before null check |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build success github build: passed
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Steve Yang Feb. 7, 2022, 8:25 a.m. UTC
  This patch fixes coverity issue by assigning the address
of the "info->data" without "info" pointer check.

CID 375065:  Null pointer dereferences  (REVERSE_INULL)
Null-checking "info" suggests that it may be null, but it has already been
dereferenced on all paths leading to the check.

Coverity issue: 375065
Fixes: fd8480e61490 ("net/ice: support module EEPROM")
Cc: stable@dpdk.org

Signed-off-by: Steve Yang <stevex.yang@intel.com>
---
 drivers/net/ice/ice_ethdev.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Qi Zhang Feb. 9, 2022, 1:42 a.m. UTC | #1
> -----Original Message-----
> From: Yang, SteveX <stevex.yang@intel.com>
> Sent: Monday, February 7, 2022 4:26 PM
> To: dev@dpdk.org
> Cc: Yang, Qiming <qiming.yang@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>; Yang, SteveX <stevex.yang@intel.com>;
> stable@dpdk.org
> Subject: [PATCH v1] net/ice: fix dereference before null check
> 
> This patch fixes coverity issue by assigning the address of the "info->data"
> without "info" pointer check.
> 
> CID 375065:  Null pointer dereferences  (REVERSE_INULL) Null-checking
> "info" suggests that it may be null, but it has already been dereferenced on
> all paths leading to the check.
> 
> Coverity issue: 375065
> Fixes: fd8480e61490 ("net/ice: support module EEPROM")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Steve Yang <stevex.yang@intel.com>

Acked-by: Qi Zhang <qi.z.zhang@intel.com>

Applied to dpdk-next-net-intel.

Thanks
Qi
  

Patch

diff --git a/drivers/net/ice/ice_ethdev.c b/drivers/net/ice/ice_ethdev.c
index d01acb8797..1a469afeac 100644
--- a/drivers/net/ice/ice_ethdev.c
+++ b/drivers/net/ice/ice_ethdev.c
@@ -5016,14 +5016,14 @@  ice_get_module_eeprom(struct rte_eth_dev *dev,
 #define I2C_USLEEP_MAX_TIME 2500
 	uint8_t value[SFF_READ_BLOCK_SIZE] = {0};
 	uint8_t addr = ICE_I2C_EEPROM_DEV_ADDR;
-	uint8_t *data = info->data;
+	uint8_t *data = NULL;
 	enum ice_status status;
 	bool is_sfp = false;
 	uint32_t i, j;
 	uint32_t offset = 0;
 	uint8_t page = 0;
 
-	if (!info || !info->length || !data)
+	if (!info || !info->length || !info->data)
 		return -EINVAL;
 
 	status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, 0, value, 1, 0,
@@ -5034,6 +5034,7 @@  ice_get_module_eeprom(struct rte_eth_dev *dev,
 	if (value[0] == ICE_MODULE_TYPE_SFP)
 		is_sfp = true;
 
+	data = info->data;
 	memset(data, 0, info->length);
 	for (i = 0; i < info->length; i += SFF_READ_BLOCK_SIZE) {
 		offset = i + info->offset;