netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/3] tg3: Handle tg3_init_rings() failures
@ 2006-07-25 22:56 Michael Chan
  2006-07-25 23:38 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Chan @ 2006-07-25 22:56 UTC (permalink / raw)
  To: davem; +Cc: sdoyon, howie, netdev

Handle dev_alloc_skb() failures when initializing the RX rings.
Without proper handling, the driver will crash when using a partial
ring.

Thanks to Stephane Doyon <sdoyon@max-t.com> for reporting the bug and
providing the initial patch.

Howie Xu <howie@vmware.com> also reported the same issue.

Signed-off-by: Michael Chan <mchan@broadcom.com>


diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 1253cec..d66b06f 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -4258,7 +4258,7 @@ static void tg3_free_rings(struct tg3 *t
  * end up in the driver.  tp->{tx,}lock are held and thus
  * we may not sleep.
  */
-static void tg3_init_rings(struct tg3 *tp)
+static int tg3_init_rings(struct tg3 *tp)
 {
 	u32 i;
 
@@ -4307,18 +4307,38 @@ static void tg3_init_rings(struct tg3 *t
 
 	/* Now allocate fresh SKBs for each rx ring. */
 	for (i = 0; i < tp->rx_pending; i++) {
-		if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD,
-				     -1, i) < 0)
+		if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_STD, -1, i) < 0) {
+			printk(KERN_WARNING PFX
+			       "%s: Using a smaller RX standard ring, "
+			       "only %d out of %d buffers were allocated "
+			       "successfully.\n",
+			       tp->dev->name, i, tp->rx_pending);
+			if (i == 0)
+				return -ENOMEM;
+			tp->rx_pending = i;
 			break;
+		}
 	}
 
 	if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) {
 		for (i = 0; i < tp->rx_jumbo_pending; i++) {
 			if (tg3_alloc_rx_skb(tp, RXD_OPAQUE_RING_JUMBO,
-					     -1, i) < 0)
+					     -1, i) < 0) {
+				printk(KERN_WARNING PFX
+				       "%s: Using a smaller RX jumbo ring, "
+				       "only %d out of %d buffers were "
+				       "allocated successfully.\n",
+				       tp->dev->name, i, tp->rx_jumbo_pending);
+				if (i == 0) {
+					tg3_free_rings(tp);
+					return -ENOMEM;
+				}
+				tp->rx_jumbo_pending = i;
 				break;
+			}
 		}
 	}
+	return 0;
 }
 
 /*
@@ -5969,7 +5989,9 @@ static int tg3_reset_hw(struct tg3 *tp, 
 	 * can only do this after the hardware has been
 	 * successfully reset.
 	 */
-	tg3_init_rings(tp);
+	err = tg3_init_rings(tp);
+	if (err)
+		return err;
 
 	/* This value is determined during the probe time DMA
 	 * engine test, tg3_test_dma.



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

* Re: [PATCH 2/3] tg3: Handle tg3_init_rings() failures
  2006-07-25 22:56 [PATCH 2/3] tg3: Handle tg3_init_rings() failures Michael Chan
@ 2006-07-25 23:38 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2006-07-25 23:38 UTC (permalink / raw)
  To: mchan; +Cc: sdoyon, howie, netdev

From: "Michael Chan" <mchan@broadcom.com>
Date: Tue, 25 Jul 2006 15:56:20 -0700

> Handle dev_alloc_skb() failures when initializing the RX rings.
> Without proper handling, the driver will crash when using a partial
> ring.
> 
> Thanks to Stephane Doyon <sdoyon@max-t.com> for reporting the bug and
> providing the initial patch.
> 
> Howie Xu <howie@vmware.com> also reported the same issue.
> 
> Signed-off-by: Michael Chan <mchan@broadcom.com>

Applied, thanks a lot.

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

end of thread, other threads:[~2006-07-25 23:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-25 22:56 [PATCH 2/3] tg3: Handle tg3_init_rings() failures Michael Chan
2006-07-25 23:38 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).