[dpdk-dev,1/1] librte_ether: fix coverity errors in rte_eth_copy_pci_info
diff mbox

Message ID 1446827408-32393-1-git-send-email-bernard.iremonger@intel.com
State Superseded, archived
Headers show

Commit Message

Bernard Iremonger Nov. 6, 2015, 4:30 p.m. UTC
add else branch to if statement.

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

Signed-off-by: Bernard Iremonger <bernard.iremonger@intel.com>
---
 lib/librte_ether/rte_ethdev.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

Comments

Thomas Monjalon Nov. 6, 2015, 4:39 p.m. UTC | #1
2015-11-06 16:30, Bernard Iremonger:
> add else branch to if statement.

I think a return statement would be more appropriate.

> Dereferencing NULL pointer reported by Coverity, CID 119256.
> Dereferencing NULL pointer reported by Coverity, CID 119257.
> 
> Signed-off-by: Bernard Iremonger <bernard.iremonger@intel.com>
[...]
>  	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;
Bernard Iremonger Nov. 6, 2015, 4:54 p.m. UTC | #2
Hi Thomas,
<snip>
> 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:
> > add else branch to if statement.
> 
> I think a return statement would be more appropriate.
> 
I will add return statement instead.

<snip>

Regards,

Bernard.

Patch
diff mbox

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index e0e1dca..8ea1f31 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -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;
+	}
 }