Skip to contentSkip to conversation

librte_ether: fix coverity errors in rte_eth_copy_pci_info

PATCH Superseded Bernard Iremonger 2 participants 3 messages Nov 6, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 librte_ether: fix coverity errors in rte_eth_copy_pci_info

add else branch to if statement.

Dereferencing NULL pointer reported by Coverity, CID 119256. Dereferencing NULL pointer reported by Coverity, CID 119257.

---
 lib/librte_ether/rte_ethdev.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
lib/librte_ether/rte_ethdev.c +12 -11
index e0e1dca..8ea1f31 100644
@@ -3271,20 +3271,21 @@ rte_eth_dev_get_dcb_info(uint8_t port_id,
 }
 
 void
-rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev)
+rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev,
+		struct rte_pci_device *pci_dev)
 {
 	if ((eth_dev == NULL) || (pci_dev == NULL)) {
 		PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
 				eth_dev, pci_dev);
-	}
-
-	eth_dev->data->dev_flags = 0;
-	if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
-		eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
-	if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
-		eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
+	} else {
+		eth_dev->data->dev_flags = 0;
+		if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
+			eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
+		if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
+			eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
 
-	eth_dev->data->kdrv = pci_dev->kdrv;
-	eth_dev->data->numa_node = pci_dev->numa_node;
-	eth_dev->data->drv_name = pci_dev->driver->name;
+		eth_dev->data->kdrv = pci_dev->kdrv;
+		eth_dev->data->numa_node = pci_dev->numa_node;
+		eth_dev->data->drv_name = pci_dev->driver->name;
+	}
 }
Signature · 1 line
1.9.1
#1 lore raw

2015-11-06 16:30, Bernard Iremonger:

Quoted 1 line

add else branch to if statement.

I think a return statement would be more appropriate.

Quoted 4 lines

Dereferencing NULL pointer reported by Coverity, CID 119256. Dereferencing NULL pointer reported by Coverity, CID 119257.

[...]

Quoted 16 lines
lib/librte_ether/rte_ethdev.c +6 -7
 	if ((eth_dev == NULL) || (pci_dev == NULL)) {
 		PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n",
 				eth_dev, pci_dev);
-	}
-
-	eth_dev->data->dev_flags = 0;
-	if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
-		eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
-	if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
-		eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
+	} else {
+		eth_dev->data->dev_flags = 0;
+		if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
+			eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
+		if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE)
+			eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
#2 lore raw

Hi Thomas,
<snip>

Quoted 8 lines

Subject: Re: [dpdk-dev] [PATCH 1/1] librte_ether: fix coverity errors in rte_eth_copy_pci_info

2015-11-06 16:30, Bernard Iremonger:

Quoted 1 line

add else branch to if statement.

I think a return statement would be more appropriate.

I will add return statement instead.

<snip>

Regards,

Bernard.