public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] remove sleep_on from drivers/net/shaper.c
@ 2004-01-17 18:43 Manfred Spraul
  0 siblings, 0 replies; only message in thread
From: Manfred Spraul @ 2004-01-17 18:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: Alan Cox

[-- Attachment #1: Type: text/plain, Size: 156 bytes --]

The shaper devices uses sleep_on for it's wait queue. The implementation
is racy, the attached patch replaces it with an explicit
add/remove_wait_queue.




[-- Attachment #2: patch-sleep_on_shaper --]
[-- Type: text/plain, Size: 969 bytes --]

--- 2.6/drivers/net/shaper.c	2004-01-17 12:19:27.000000000 +0100
+++ build-2.6/drivers/net/shaper.c	2004-01-17 12:34:19.000000000 +0100
@@ -83,6 +83,7 @@
 #include <linux/if_arp.h>
 #include <linux/init.h>
 #include <linux/if_shaper.h>
+#include <linux/wait.h>
 
 #include <net/dst.h>
 #include <net/arp.h>
@@ -106,17 +107,27 @@
  
 static int shaper_lock(struct shaper *sh)
 {
+	DECLARE_WAITQUEUE(wait, current);
+
 	/*
 	 *	Lock in an interrupt must fail
 	 */
-	while (test_and_set_bit(0, &sh->locked))
-	{
-		if (!in_interrupt())
-			sleep_on(&sh->wait_queue);
-		else
+	if (in_interrupt()) {
+		if (test_and_set_bit(0, &sh->locked)) {
 			return 0;
-			
+		} else {
+			return 1;
+		}
+	}
+	add_wait_queue(&sh->wait_queue, &wait);
+	for (;;) {
+		set_current_state(TASK_UNINTERRUPTIBLE);
+		if (test_and_set_bit(0, &sh->locked) == 0)
+			break;
+		schedule();
 	}
+	remove_wait_queue(&sh->wait_queue, &wait);
+	__set_current_state(TASK_RUNNING);
 	return 1;
 }
 


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-01-17 18:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-17 18:43 [PATCH] remove sleep_on from drivers/net/shaper.c Manfred Spraul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox