Skip to contentSkip to conversation

raw/ntb: fix null pointer dereference

PATCH Applied Xiaoyun Li 3 participants 3 messages Aug 5, 2019 – Aug 6, 2019

lore
Share & tools
lore

Xiaoyun Li

author
#0 lore raw

PATCH 1/1 raw/ntb: fix null pointer dereference

This patch fixes null pointer dereference issues found by coverity scan.

Coverity issue: 344981, 344991, 345000, 345002, 345006, 345024

Fixes 277310027965 ("raw/ntb: introduce NTB raw device driver")
---
 drivers/raw/ntb/ntb.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/raw/ntb/ntb.c +11 -7
index 4ba2f3a38..bfecce1e4 100644
@@ -447,14 +447,16 @@ static int
 ntb_attr_set(struct rte_rawdev *dev, const char *attr_name,
 				 uint64_t attr_value)
 {
-	struct ntb_hw *hw = dev->dev_private;
-	int index = 0;
+	struct ntb_hw *hw;
+	int index;
 
 	if (dev == NULL || attr_name == NULL) {
 		NTB_LOG(ERR, "Invalid arguments for setting attributes");
 		return -EINVAL;
 	}
 
+	hw = dev->dev_private;
+
 	if (!strncmp(attr_name, NTB_SPAD_USER, NTB_SPAD_USER_LEN)) {
 		if (hw->ntb_ops->spad_write == NULL)
 			return -ENOTSUP;
@@ -475,14 +477,16 @@ static int
 ntb_attr_get(struct rte_rawdev *dev, const char *attr_name,
 				 uint64_t *attr_value)
 {
-	struct ntb_hw *hw = dev->dev_private;
-	int index = 0;
+	struct ntb_hw *hw;
+	int index;
 
 	if (dev == NULL || attr_name == NULL || attr_value == NULL) {
 		NTB_LOG(ERR, "Invalid arguments for getting attributes");
 		return -EINVAL;
 	}
 
+	hw = dev->dev_private;
+
 	if (!strncmp(attr_name, NTB_TOPO_NAME, NTB_ATTR_NAME_LEN)) {
 		*attr_value = hw->topo;
 		NTB_LOG(INFO, "Attribute (%s) Value (%" PRIu64 ")",
@@ -735,7 +739,7 @@ ntb_create(struct rte_pci_device *pci_dev, int socket_id)
 
 	if (pci_dev == NULL) {
 		NTB_LOG(ERR, "Invalid pci_dev.");
-		ret = -EINVAL;
+		return -EINVAL;
 	}
 
 	memset(name, 0, sizeof(name));
@@ -750,7 +754,7 @@ ntb_create(struct rte_pci_device *pci_dev, int socket_id)
 					 socket_id);
 	if (rawdev == NULL) {
 		NTB_LOG(ERR, "Unable to allocate rawdev.");
-		ret = -EINVAL;
+		return -EINVAL;
 	}
 
 	rawdev->dev_ops = &ntb_ops;
@@ -766,7 +770,7 @@ ntb_create(struct rte_pci_device *pci_dev, int socket_id)
 	return ret;
 
 fail:
-	if (rawdev)
+	if (rawdev != NULL)
 		rte_rawdev_pmd_release(rawdev);
 
 	return ret;
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 77 lines · Xiaoyun Li

This patch fixes null pointer dereference issues found by coverity scan.

Coverity issue: 344981, 344991, 345000, 345002, 345006, 345024

Fixes 277310027965 ("raw/ntb: introduce NTB raw device driver")

---
drivers/raw/ntb/ntb.c | 18 +++++++++++-------

1 file changed, 11 insertions(+), 7 deletions(-)
drivers/raw/ntb/ntb.c +10 -6
index 4ba2f3a38..bfecce1e4 100644
@@ -447,14 +447,16 @@ static int
 ntb_attr_set(struct rte_rawdev *dev, const char *attr_name,
 				 uint64_t attr_value)
 {
-	struct ntb_hw *hw = dev->dev_private;
-	int index = 0;
+	struct ntb_hw *hw;
+	int index;
 
 	if (dev == NULL || attr_name == NULL) {
 		NTB_LOG(ERR, "Invalid arguments for setting attributes");
 		return -EINVAL;
 	}
 
+	hw = dev->dev_private;
+
 	if (!strncmp(attr_name, NTB_SPAD_USER, NTB_SPAD_USER_LEN)) {
 		if (hw->ntb_ops->spad_write == NULL)
 			return -ENOTSUP;
@@ -475,14 +477,16 @@ static int
 ntb_attr_get(struct rte_rawdev *dev, const char *attr_name,
 				 uint64_t *attr_value)
 {
-	struct ntb_hw *hw = dev->dev_private;
-	int index = 0;
+	struct ntb_hw *hw;
+	int index;
 
 	if (dev == NULL || attr_name == NULL || attr_value == NULL) {
 		NTB_LOG(ERR, "Invalid arguments for getting attributes");
 		return -EINVAL;
 	}
 
+	hw = dev->dev_private;
+
 	if (!strncmp(attr_name, NTB_TOPO_NAME, NTB_ATTR_NAME_LEN)) {
 		*attr_value = hw->topo;
 		NTB_LOG(INFO, "Attribute (%s) Value (%" PRIu64 ")",
@@ -735,7 +739,7 @@ ntb_create(struct rte_pci_device *pci_dev, int socket_id)
 
 	if (pci_dev == NULL) {
 		NTB_LOG(ERR, "Invalid pci_dev.");
-		ret = -EINVAL;
+		return -EINVAL;
 	}
 
 	memset(name, 0, sizeof(name));
@@ -750,7 +754,7 @@ ntb_create(struct rte_pci_device *pci_dev, int socket_id)
 					 socket_id);
 	if (rawdev == NULL) {
 		NTB_LOG(ERR, "Unable to allocate rawdev.");
-		ret = -EINVAL;
+		return -EINVAL;
 	}
 
 	rawdev->dev_ops = &ntb_ops;
@@ -766,7 +770,7 @@ ntb_create(struct rte_pci_device *pci_dev, int socket_id)
 	return ret;
 

fail:

drivers/raw/ntb/ntb.c +1 -1
-	if (rawdev)
+	if (rawdev != NULL)
Quoted 6 lines
		rte_rawdev_pmd_release(rawdev);

	return ret;
Signature · 1 line
2.17.1