Fix defects found by coverity scan
cover 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.
Wei Huang (2):
raw/ifpga/base: unlock mutex when nios init fail raw/ifpga/base: check pointer adapter before derefence
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 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 v1 1/2] raw/ifpga/base: unlock mutex when nios init fail
Quoted 30 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of Wei Huang
Sent: 2020年11月5日 9:49
To: [email protected]; Xu, Rosen <[email protected]>; Zhang, Qi Z <[email protected]>
Cc: [email protected]; Huang, Wei <[email protected]>
Subject: [dpdk-dev] [PATCH v1 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 inmulti-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 +0
-0
drivers/raw/ifpga/base/ifpga_fme.c static int fme_nios_spi_init(struct ifpga_feature · line 1122
Quoted 8 lines
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; }
Quoted 2 lines
--
2.29.2
PATCH 2/2 raw/ifpga/base: check pointer adapter before derefence
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 derefence it.
Coverity issue: 363752
--- 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 v1 2/2] raw/ifpga/base: check pointer adapter before derefence
Quoted 33 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of Wei Huang
Sent: 2020年11月5日 9:49
To: [email protected]; Xu, Rosen <[email protected]>; Zhang, Qi Z <[email protected]>
Cc: [email protected]; Huang, Wei <[email protected]>
Subject: [dpdk-dev] [PATCH v1 2/2] raw/ifpga/base: check pointer adapter before derefenceIn
opae_adapter_destroy(), pointer "adapter" is not validated before passing it toopae_adapter_shm_free()andopae_adapter_mutex_close()which derefence it.Fixes e41856b515ce ("raw/ifpga/base: enhance driver reliability inmulti-process") Coverity issue: 363752
Signed-off-by Wei Huang <[email protected]>--- drivers/raw/ifpga/base/opae_hw_api.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/raw/ifpga/base/opae_hw_api.c +0
-1@@ -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)
drivers/raw/ifpga/base/opae_hw_api.c int opae_adapter_enumerate(struct opae_adapter · line 614
Quoted 10 lines
drivers/raw/ifpga/base/opae_hw_api.c +6
-3- 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); + } }