[dpdk-dev,v3] net/ring: remove unnecessary NULL check

Message ID 1478094369-3943-1-git-send-email-mauricio.vasquez@polito.it (mailing list archive)
State Accepted, archived
Headers

Commit Message

Mauricio Vasquez Nov. 2, 2016, 1:46 p.m. UTC
  Coverity detected this as an issue because internals->data will never be NULL,
then the check is not necessary.

Fixes: d082c0395bf6 ("ring: fix memory leak when detaching")
Coverity issue: 137873

Signed-off-by: Mauricio Vasquez B <mauricio.vasquez@polito.it>
---
 drivers/net/ring/rte_eth_ring.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)
  

Comments

Ferruh Yigit Nov. 2, 2016, 2:05 p.m. UTC | #1
On 11/2/2016 1:46 PM, Mauricio Vasquez B wrote:
> Coverity detected this as an issue because internals->data will never be NULL,
> then the check is not necessary.
> 
> Fixes: d082c0395bf6 ("ring: fix memory leak when detaching")
> Coverity issue: 137873
> 
> Signed-off-by: Mauricio Vasquez B <mauricio.vasquez@polito.it>
> ---

Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
  
Thomas Monjalon Nov. 7, 2016, 1:08 p.m. UTC | #2
2016-11-02 14:05, Ferruh Yigit:
> On 11/2/2016 1:46 PM, Mauricio Vasquez B wrote:
> > Coverity detected this as an issue because internals->data will never be NULL,
> > then the check is not necessary.
> > 
> > Fixes: d082c0395bf6 ("ring: fix memory leak when detaching")
> > Coverity issue: 137873
> > 
> > Signed-off-by: Mauricio Vasquez B <mauricio.vasquez@polito.it>
> 
> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied, thanks
  

Patch

diff --git a/drivers/net/ring/rte_eth_ring.c b/drivers/net/ring/rte_eth_ring.c
index 6d2a8c1..c1767c4 100644
--- a/drivers/net/ring/rte_eth_ring.c
+++ b/drivers/net/ring/rte_eth_ring.c
@@ -599,24 +599,22 @@  rte_pmd_ring_remove(const char *name)
 
 	eth_dev_stop(eth_dev);
 
-	if (eth_dev->data) {
-		internals = eth_dev->data->dev_private;
-		if (internals->action == DEV_CREATE) {
-			/*
-			 * it is only necessary to delete the rings in rx_queues because
-			 * they are the same used in tx_queues
-			 */
-			for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
-				r = eth_dev->data->rx_queues[i];
-				rte_ring_free(r->rng);
-			}
+	internals = eth_dev->data->dev_private;
+	if (internals->action == DEV_CREATE) {
+		/*
+		 * it is only necessary to delete the rings in rx_queues because
+		 * they are the same used in tx_queues
+		 */
+		for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
+			r = eth_dev->data->rx_queues[i];
+			rte_ring_free(r->rng);
 		}
-
-		rte_free(eth_dev->data->rx_queues);
-		rte_free(eth_dev->data->tx_queues);
-		rte_free(eth_dev->data->dev_private);
 	}
 
+	rte_free(eth_dev->data->rx_queues);
+	rte_free(eth_dev->data->tx_queues);
+	rte_free(eth_dev->data->dev_private);
+
 	rte_free(eth_dev->data);
 
 	rte_eth_dev_release_port(eth_dev);