Skip to contentSkip to conversation

raw/ifpga/base: check pointer before dereference

PATCH Applied Wei Huang 4 participants 4 messages Jun 23, 2022 – Jun 26, 2022

lore
Share & tools
lore

Wei Huang

author
#0 lore raw

PATCH 1/1 raw/ifpga/base: check pointer before dereference

Do null-checking on hw->adapter in fme_pmci_init() before dereference it.

Coverity issue: 379202

Fixes ca6eb0f7c836 ("raw/ifpga/base: add PMCI base driver")
---
 drivers/raw/ifpga/base/ifpga_fme.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/raw/ifpga/base/ifpga_fme.c +2 -2
index 25ff819..b6dd4ce 100644
@@ -1591,7 +1591,7 @@ static int fme_pmci_init(struct ifpga_feature *feature)
 	int ret = 0;
 
 	hw = fme->parent;
-	if (!hw)
+	if (!hw || !hw->adapter)
 		return -ENODEV;
 
 	mgr = hw->adapter->mgr;
@@ -1608,7 +1608,7 @@ static int fme_pmci_init(struct ifpga_feature *feature)
 
 	max10->type = M10_N6000;
 	max10->mmio = feature->addr;
-	if (hw->adapter && hw->adapter->shm.ptr) {
+	if (hw->adapter->shm.ptr) {
 		sd = (opae_share_data *)hw->adapter->shm.ptr;
 		max10->bmc_ops.mutex = &sd->spi_mutex;
 	} else {
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#1 lore raw
Quoted 46 lines

-----Original Message-----
From: Huang, Wei <[email protected]>
Sent: Thursday, June 23, 2022 11:12 AM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Xu, Rosen <[email protected]>; Zhang, Tianfei <[email protected]>; Zhang, Qi Z <[email protected]>; Huang, Wei <[email protected]>
Subject: [PATCH] raw/ifpga/base: check pointer before dereference

Do null-checking on hw->adapter in fme_pmci_init() before dereference it.

Coverity issue: 379202

Fixes ca6eb0f7c836 ("raw/ifpga/base: add PMCI base driver")
---
 drivers/raw/ifpga/base/ifpga_fme.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/raw/ifpga/base/ifpga_fme.c +1 -1
index 25ff819..b6dd4ce 100644
@@ -1591,7 +1591,7 @@ static int fme_pmci_init(struct ifpga_feature
 *feature)
 	int ret = 0;
 
 	hw = fme->parent;
-	if (!hw)
+	if (!hw || !hw->adapter)
 		return -ENODEV;
 
drivers/raw/ifpga/base/ifpga_fme.c +1 -1
 	mgr = hw->adapter->mgr;
@@ -1608,7 +1608,7 @@ static int fme_pmci_init(struct ifpga_feature
 *feature)
 
 	max10->type = M10_N6000;
 	max10->mmio = feature->addr;
-	if (hw->adapter && hw->adapter->shm.ptr) {
+	if (hw->adapter->shm.ptr) {
 		sd = (opae_share_data *)hw->adapter->shm.ptr;
 		max10->bmc_ops.mutex = &sd->spi_mutex;
Quoted 3 lines

} else {
--
1.8.3.1

It looks good for me.

Acked-by on v1 1/1
#3 lore raw
In reply to Wei Huang

Hi,

Quoted 44 lines

-----Original Message-----
From: Huang, Wei <[email protected]>
Sent: Thursday, June 23, 2022 11:12
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Xu, Rosen <[email protected]>; Zhang, Tianfei <[email protected]>; Zhang, Qi Z <[email protected]>; Huang, Wei <[email protected]>
Subject: [PATCH] raw/ifpga/base: check pointer before dereference

Do null-checking on hw->adapter in fme_pmci_init() before dereference it.

Coverity issue: 379202

Fixes ca6eb0f7c836 ("raw/ifpga/base: add PMCI base driver")
---
 drivers/raw/ifpga/base/ifpga_fme.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/raw/ifpga/base/ifpga_fme.c +1 -1
index 25ff819..b6dd4ce 100644
@@ -1591,7 +1591,7 @@ static int fme_pmci_init(struct ifpga_feature
 *feature)
 	int ret = 0;
 
 	hw = fme->parent;
-	if (!hw)
+	if (!hw || !hw->adapter)
 		return -ENODEV;
 
drivers/raw/ifpga/base/ifpga_fme.c +1 -1
 	mgr = hw->adapter->mgr;
@@ -1608,7 +1608,7 @@ static int fme_pmci_init(struct ifpga_feature
 *feature)
 
 	max10->type = M10_N6000;
 	max10->mmio = feature->addr;
-	if (hw->adapter && hw->adapter->shm.ptr) {
+	if (hw->adapter->shm.ptr) {
 		sd = (opae_share_data *)hw->adapter->shm.ptr;
 		max10->bmc_ops.mutex = &sd->spi_mutex;
Quoted 3 lines

} else {
--
1.8.3.1