[PATCH] remove sleep_on from drivers/net/shaper.c

From: Manfred Spraul
Date: Sat Jan 17 2004 - 13:46:52 EST


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.



--- 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;
}