[PATCH 2/2]: Spider ethernet driver -- protect chain head

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Please review/apply/ack/forward upstream.

--linas


Prevent a potential race. If two threads are both calling
the transmit routine, both can potentially try to grab the
same dma descriptor. Serialize access to the head of the
tx ring with spinlocks.

Signed-off-by: Linas Vepstas <[email protected]>

----
 drivers/net/spider_net.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

Index: linux-2.6.17-rc1/drivers/net/spider_net.c
===================================================================
--- linux-2.6.17-rc1.orig/drivers/net/spider_net.c	2006-04-21 18:32:46.000000000 -0500
+++ linux-2.6.17-rc1/drivers/net/spider_net.c	2006-04-21 18:39:12.000000000 -0500
@@ -806,13 +806,19 @@ spider_net_stop(struct net_device *netde
 static struct spider_net_descr *
 spider_net_get_next_tx_descr(struct spider_net_card *card)
 {
+	struct spider_net_descr *descr;
+	spin_lock(&card->tx_chain_lock);
+
+	descr = card->tx_chain.head;
 	/* check, if head points to not-in-use descr */
 	if ( spider_net_get_descr_status(card->tx_chain.head) ==
 	     SPIDER_NET_DESCR_NOT_IN_USE ) {
-		return card->tx_chain.head;
+		card->tx_chain.head = descr->next;
 	} else {
-		return NULL;
+		descr = NULL;
 	}
+	spin_unlock(&card->tx_chain_lock);
+	return descr;
 }
 
 /**
@@ -932,8 +938,6 @@ spider_net_xmit(struct sk_buff *skb, str
 	if (result)
 		goto error;
 
-	card->tx_chain.head = card->tx_chain.head->next;
-
 	if (spider_net_get_descr_status(descr->prev) !=
 	    SPIDER_NET_DESCR_CARDOWNED) {
 		/* make sure the current descriptor is in memory. Then
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux