Subject: [PATCH] 3c515: Write outside array bounds

From: Roel Kluin <[email-masked]>
Date: Sun, 26 Jul 2009 00:35:29 +0200

if dev_alloc_skb() fails on the first iteration, a write to
cp->rx_ring[-1] occurs.

Signed-off-by: Roel Kluin <[email-masked]>
---
Please review: can we error return like this?

diff --git a/drivers/net/3c515.c b/drivers/net/3c515.c
index 3e00fa8..c84815a 100644
--- a/drivers/net/3c515.c
+++ b/drivers/net/3c515.c
@@ -827,7 +827,7 @@ static int corkscrew_open(struct net_device *dev)
 			skb = dev_alloc_skb(PKT_BUF_SZ);
 			vp->rx_skbuff[i] = skb;
 			if (skb == NULL)
-				break;	/* Bad news!  */
+				return -ENOMEM;	/* Bad news!  */
 			skb->dev = dev;	/* Mark as being used by this device. */
 			skb_reserve(skb, 2);	/* Align IP on 16 byte boundaries */
 			vp->rx_ring[i].addr = isa_virt_to_bus(skb->data);