raw/ifpga/base: fix defects found by coverity scan
v2 cover raw/ifpga/base: fix defects found by coverity scan
Two issues are introduced from previous patch, one resides in ifpga_fme.c and the other resides in opae_hw_api.c. Below two patches are provided to fix them separately.
Main changes from v2:
- Fix coding style issue
Wei Huang (2):
raw/ifpga/base: unlock mutex when nios init fail raw/ifpga/base: check pointer adapter before dereference
drivers/raw/ifpga/base/ifpga_fme.c | 2 ++ drivers/raw/ifpga/base/opae_hw_api.c | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-)
Signature · 1 line
2.29.2
PATCH v2 1/2 raw/ifpga/base: unlock mutex when nios init fail
In fme_nios_spi_init(), a mutex is locked for protecting nios initialization process, the mutex is only unlocked when process is successful, it should also be unlocked when process fail.
Coverity issue: 363751
--- drivers/raw/ifpga/base/ifpga_fme.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/raw/ifpga/base/ifpga_fme.c +2 -0
@@ -1115,6 +1115,8 @@ static int fme_nios_spi_init(struct ifpga_feature *feature) ret =nios_spi_wait_init_done (spi_master);if (ret !=0 ) {dev_err (fme,"FME NIOS_SPI init fail\n" ); +if (spi_master->mutex) +pthread_mutex_unlock (spi_master->mutex); goto release_dev; }
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v2 1/2] raw/ifpga/base: unlock mutex when nios init fail
Hi,
Quoted 36 lines
-----Original Message-----
From: Huang, Wei <[email protected]>
Sent: Thursday, November 05, 2020 10:06
To: [email protected]; Xu, Rosen <[email protected]>; Zhang, Qi Z <[email protected]>
Cc: [email protected]; Huang, Wei <[email protected]>
Subject: [PATCH v2 1/2] raw/ifpga/base: unlock mutex when nios init failIn
fme_nios_spi_init(), a mutex is locked for protecting nios initialization process, the mutex is only unlocked when process is successful, it should also be unlocked when process fail.Fixes e41856b515ce ("raw/ifpga/base: enhance driver reliability in multi-process") Coverity issue: 363751
Signed-off-by Wei Huang <[email protected]>--- drivers/raw/ifpga/base/ifpga_fme.c | 2 ++ 1 file changed, 2 insertions(+)drivers/raw/ifpga/base/ifpga_fme.c +2
-1@@ -1115,6 +1115,8 @@ static int fme_nios_spi_init(struct ifpga_feature *feature) ret =nios_spi_wait_init_done (spi_master);if (ret !=0 ) {dev_err (fme,"FME NIOS_SPI init fail\n" ); +if (spi_master->mutex) +pthread_mutex_unlock (spi_master->mutex); goto release_dev; } --
Quoted 1 line
2.29.2
PATCH v2 2/2 raw/ifpga/base: check pointer adapter before dereference
In reply to Wei HuangIn opae_adapter_destroy(), pointer "adapter" is not validated before passing it to opae_adapter_shm_free() and opae_adapter_mutex_close() which dereference it.
Coverity issue: 363752
---
v2: fix typo in commit log
--- drivers/raw/ifpga/base/opae_hw_api.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/raw/ifpga/base/opae_hw_api.c +6 -4
@@ -605,10 +605,12 @@ int opae_adapter_enumerate(struct opae_adapter *adapter)*/ void opae_adapter_destroy (struct opae_adapter *adapter) { -if (adapter && adapter->ops && adapter->ops->destroy) - adapter->ops->destroy (adapter); -opae_adapter_shm_free (adapter); -opae_adapter_mutex_close (adapter); +if (adapter) { +if (adapter->ops && adapter->ops->destroy) + adapter->ops->destroy (adapter); +opae_adapter_shm_free (adapter); +opae_adapter_mutex_close (adapter); + } }/**
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v2 2/2] raw/ifpga/base: check pointer adapter before dereference
Hi,
Quoted 46 lines
-----Original Message-----
From: Huang, Wei <[email protected]>
Sent: Thursday, November 05, 2020 10:06
To: [email protected]; Xu, Rosen <[email protected]>; Zhang, Qi Z <[email protected]>
Cc: [email protected]; Huang, Wei <[email protected]>
Subject: [PATCH v2 2/2] raw/ifpga/base: check pointer adapter before dereferenceIn
opae_adapter_destroy(), pointer "adapter" is not validated before passing it toopae_adapter_shm_free()andopae_adapter_mutex_close()which dereference it.Fixes e41856b515ce ("raw/ifpga/base: enhance driver reliability in multi-process") Coverity issue: 363752
Signed-off-by Wei Huang <[email protected]>---
v2: fix typo in commit log--- drivers/raw/ifpga/base/opae_hw_api.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/raw/ifpga/base/opae_hw_api.c +6
-5@@ -605,10 +605,12 @@ int opae_adapter_enumerate(struct opae_adapter*adapter) */ void opae_adapter_destroy (struct opae_adapter *adapter) { -if (adapter && adapter->ops && adapter->ops->destroy) - adapter->ops->destroy (adapter); -opae_adapter_shm_free (adapter); -opae_adapter_mutex_close (adapter); +if (adapter) { +if (adapter->ops && adapter->ops->destroy) + adapter->ops->destroy (adapter); +opae_adapter_shm_free (adapter); +opae_adapter_mutex_close (adapter); + } }/** --
Quoted 1 line
2.29.2
Zhang, Qi Z
AppliedQuoted 21 lines
-----Original Message-----
From: Huang, Wei <[email protected]>
Sent: Thursday, November 5, 2020 10:06 AM
To: [email protected]; Xu, Rosen <[email protected]>; Zhang, Qi Z <[email protected]>
Cc: [email protected]; Huang, Wei <[email protected]>
Subject: [PATCH v2 0/2] raw/ifpga/base: fix defects found by coverity scanTwo issues are introduced from previous patch, one resides in
ifpga_fme.cand the other resides inopae_hw_api.c. Below two patches are provided to fix them separately.Main changes from v2:
- Fix coding style issueWei Huang (2):
raw/ifpga/base: unlock mutex when nios init fail raw/ifpga/base: check pointer adapter before dereference
Quoted 6 lines
drivers/raw/ifpga/base/ifpga_fme.c | 2 ++ drivers/raw/ifpga/base/opae_hw_api.c | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-)--
2.29.2
Applied to dpdk-next-net-intel.
Thanks
Qi