[v1,4/4] raw/ifpga/base: check pointer before dereferencing

Message ID 1615969296-17021-5-git-send-email-wei.huang@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Qi Zhang
Headers
Series Fix coverity issues reported in DPDK-26380 |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/travis-robot success travis build: passed
ci/github-robot success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Wei Huang March 17, 2021, 8:21 a.m. UTC
  In init_sec_mgr(), pointer "hw" may be NULL, so "hw" should
be checked before dereferencing.

Coverity issue: 367483
Fixes: 7a4f3993f269 ("raw/ifpga: add FPGA RSU APIs")

Signed-off-by: Wei Huang <wei.huang@intel.com>
---
 drivers/raw/ifpga/base/ifpga_sec_mgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Zhang, Tianfei April 1, 2021, 7:47 a.m. UTC | #1
> -----Original Message-----
> From: Huang, Wei <wei.huang@intel.com>
> Sent: 2021年3月17日 16:22
> To: dev@dpdk.org; Xu, Rosen <rosen.xu@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>
> Cc: stable@dpdk.org; Zhang, Tianfei <tianfei.zhang@intel.com>; Huang, Wei
> <wei.huang@intel.com>
> Subject: [PATCH v1 4/4] raw/ifpga/base: check pointer before dereferencing
> 
> In init_sec_mgr(), pointer "hw" may be NULL, so "hw" should be checked
> before dereferencing.
> 
> Coverity issue: 367483
> Fixes: 7a4f3993f269 ("raw/ifpga: add FPGA RSU APIs")
> 
> Signed-off-by: Wei Huang <wei.huang@intel.com>
> ---
>  drivers/raw/ifpga/base/ifpga_sec_mgr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/raw/ifpga/base/ifpga_sec_mgr.c
> b/drivers/raw/ifpga/base/ifpga_sec_mgr.c
> index 4cf1db3049..15fb5b6d4d 100644
> --- a/drivers/raw/ifpga/base/ifpga_sec_mgr.c
> +++ b/drivers/raw/ifpga/base/ifpga_sec_mgr.c
> @@ -610,7 +610,7 @@ int init_sec_mgr(struct ifpga_fme_hw *fme)
>  		smgr->rsu_status = NULL;
>  	}
> 
> -	if ((hw->pci_data->device_id == IFPGA_N3000_DID) &&
> +	if (hw && (hw->pci_data->device_id == IFPGA_N3000_DID) &&
>  		(hw->pci_data->vendor_id == IFPGA_N3000_VID)) {
>  		smgr->ops = &n3000_sec_ops;
>  		smgr->copy_speed = IFPGA_N3000_COPY_SPEED;
> --

Acked-by: Tianfei zhang <Tianfei.zhang@intel.com>
  
Xu, Rosen April 1, 2021, 8:48 a.m. UTC | #2
Hi,

-----Original Message-----
From: Huang, Wei <wei.huang@intel.com> 
Sent: Wednesday, March 17, 2021 4:22 PM
To: dev@dpdk.org; Xu, Rosen <rosen.xu@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
Cc: stable@dpdk.org; Zhang, Tianfei <tianfei.zhang@intel.com>; Huang, Wei <wei.huang@intel.com>
Subject: [PATCH v1 4/4] raw/ifpga/base: check pointer before dereferencing

In init_sec_mgr(), pointer "hw" may be NULL, so "hw" should be checked before dereferencing.

Coverity issue: 367483
Fixes: 7a4f3993f269 ("raw/ifpga: add FPGA RSU APIs")

Signed-off-by: Wei Huang <wei.huang@intel.com>
---
 drivers/raw/ifpga/base/ifpga_sec_mgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/raw/ifpga/base/ifpga_sec_mgr.c b/drivers/raw/ifpga/base/ifpga_sec_mgr.c
index 4cf1db3049..15fb5b6d4d 100644
--- a/drivers/raw/ifpga/base/ifpga_sec_mgr.c
+++ b/drivers/raw/ifpga/base/ifpga_sec_mgr.c
@@ -610,7 +610,7 @@ int init_sec_mgr(struct ifpga_fme_hw *fme)
 		smgr->rsu_status = NULL;
 	}
 
-	if ((hw->pci_data->device_id == IFPGA_N3000_DID) &&
+	if (hw && (hw->pci_data->device_id == IFPGA_N3000_DID) &&
 		(hw->pci_data->vendor_id == IFPGA_N3000_VID)) {
 		smgr->ops = &n3000_sec_ops;
 		smgr->copy_speed = IFPGA_N3000_COPY_SPEED;
--
2.29.2

Acked-by: Rosen Xu <rosen.xu@intel.com>
  

Patch

diff --git a/drivers/raw/ifpga/base/ifpga_sec_mgr.c b/drivers/raw/ifpga/base/ifpga_sec_mgr.c
index 4cf1db3049..15fb5b6d4d 100644
--- a/drivers/raw/ifpga/base/ifpga_sec_mgr.c
+++ b/drivers/raw/ifpga/base/ifpga_sec_mgr.c
@@ -610,7 +610,7 @@  int init_sec_mgr(struct ifpga_fme_hw *fme)
 		smgr->rsu_status = NULL;
 	}
 
-	if ((hw->pci_data->device_id == IFPGA_N3000_DID) &&
+	if (hw && (hw->pci_data->device_id == IFPGA_N3000_DID) &&
 		(hw->pci_data->vendor_id == IFPGA_N3000_VID)) {
 		smgr->ops = &n3000_sec_ops;
 		smgr->copy_speed = IFPGA_N3000_COPY_SPEED;