All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: xgene: fix possible NULL dereference in xgene_enet_free_desc_rings()
@ 2014-08-21 20:44 Iyappan Subramanian
  2014-08-22 18:25 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Iyappan Subramanian @ 2014-08-21 20:44 UTC (permalink / raw)
  To: davem, netdev; +Cc: dan.carpenter, Iyappan Subramanian

A NULL pointer dereference is possible for the argument ring->buf_pool
which is passed to xgene_enet_free_desc_ring(), as ring could be NULL.

And now since NULL pointers are being checked for before the calls to
xgene_enet_free_desc_ring(), might as well take advantage of them and
not call the function if the argument would be NULL.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Iyappan Subramanian <isubramanian@apm.com>
---
 drivers/net/ethernet/apm/xgene/xgene_enet_main.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
index e1a8f4e..e4222af 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
@@ -563,15 +563,21 @@ static void xgene_enet_free_desc_rings(struct xgene_enet_pdata *pdata)
 	struct xgene_enet_desc_ring *ring;
 
 	ring = pdata->tx_ring;
-	if (ring && ring->cp_ring && ring->cp_ring->cp_skb)
-		devm_kfree(dev, ring->cp_ring->cp_skb);
-	xgene_enet_free_desc_ring(ring);
+	if (ring) {
+		if (ring->cp_ring && ring->cp_ring->cp_skb)
+			devm_kfree(dev, ring->cp_ring->cp_skb);
+		xgene_enet_free_desc_ring(ring);
+	}
 
 	ring = pdata->rx_ring;
-	if (ring && ring->buf_pool && ring->buf_pool->rx_skb)
-		devm_kfree(dev, ring->buf_pool->rx_skb);
-	xgene_enet_free_desc_ring(ring->buf_pool);
-	xgene_enet_free_desc_ring(ring);
+	if (ring) {
+		if (ring->buf_pool) {
+			if (ring->buf_pool->rx_skb)
+				devm_kfree(dev, ring->buf_pool->rx_skb);
+			xgene_enet_free_desc_ring(ring->buf_pool);
+		}
+		xgene_enet_free_desc_ring(ring);
+	}
 }
 
 static struct xgene_enet_desc_ring *xgene_enet_create_desc_ring(
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] net: xgene: fix possible NULL dereference in xgene_enet_free_desc_rings()
  2014-08-21 20:44 [PATCH] net: xgene: fix possible NULL dereference in xgene_enet_free_desc_rings() Iyappan Subramanian
@ 2014-08-22 18:25 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2014-08-22 18:25 UTC (permalink / raw)
  To: isubramanian; +Cc: netdev, dan.carpenter

From: Iyappan Subramanian <isubramanian@apm.com>
Date: Thu, 21 Aug 2014 13:44:48 -0700

> A NULL pointer dereference is possible for the argument ring->buf_pool
> which is passed to xgene_enet_free_desc_ring(), as ring could be NULL.
> 
> And now since NULL pointers are being checked for before the calls to
> xgene_enet_free_desc_ring(), might as well take advantage of them and
> not call the function if the argument would be NULL.
> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Iyappan Subramanian <isubramanian@apm.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-08-22 18:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-21 20:44 [PATCH] net: xgene: fix possible NULL dereference in xgene_enet_free_desc_rings() Iyappan Subramanian
2014-08-22 18:25 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.