public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Manfred Spraul <manfred@colorfullife.com>
To: linux-kernel@vger.kernel.org
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Subject: [PATCH] remove sleep_on from drivers/net/shaper.c
Date: Sat, 17 Jan 2004 19:43:37 +0100	[thread overview]
Message-ID: <40098259.9020405@colorfullife.com> (raw)

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


                 reply	other threads:[~2004-01-17 18:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=40098259.9020405@colorfullife.com \
    --to=manfred@colorfullife.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox