public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@vyatta.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 7/8] floppy: use wait_event_interruptible
Date: Wed, 09 Jun 2010 11:34:56 -0700	[thread overview]
Message-ID: <20100609183626.205751245@vyatta.com> (raw)
In-Reply-To: 20100609183449.110905403@vyatta.com

[-- Attachment #1: floppy-wait-event.patch --]
[-- Type: text/plain, Size: 2526 bytes --]

Convert wait loops to use wait_event_ macros.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

--- a/drivers/block/floppy.c	2010-06-09 11:34:11.326812498 -0700
+++ b/drivers/block/floppy.c	2010-06-09 11:34:12.416645239 -0700
@@ -514,8 +514,6 @@ static unsigned long fdc_busy;
 static DECLARE_WAIT_QUEUE_HEAD(fdc_wait);
 static DECLARE_WAIT_QUEUE_HEAD(command_done);
 
-#define NO_SIGNAL (!interruptible || !signal_pending(current))
-
 /* Errors during formatting are counted here. */
 static int format_errors;
 
@@ -858,36 +856,15 @@ static void set_fdc(int drive)
 }
 
 /* locks the driver */
-static int _lock_fdc(int drive, bool interruptible, int line)
+static int lock_fdc(int drive, bool interruptible)
 {
-	if (atomic_read(&usage_count) == 0) {
-		pr_err("Trying to lock fdc while usage count=0 at line %d\n",
-		       line);
+	if (WARN(atomic_read(&usage_count) == 0,
+		 "Trying to lock fdc while usage count=0\n"))
 		return -1;
-	}
 
-	if (test_and_set_bit(0, &fdc_busy)) {
-		DECLARE_WAITQUEUE(wait, current);
-		add_wait_queue(&fdc_wait, &wait);
-
-		for (;;) {
-			set_current_state(TASK_INTERRUPTIBLE);
-
-			if (!test_and_set_bit(0, &fdc_busy))
-				break;
-
-			schedule();
-
-			if (!NO_SIGNAL) {
-				remove_wait_queue(&fdc_wait, &wait);
-				return -EINTR;
-			}
-		}
+	if (wait_event_interruptible(fdc_wait, !test_and_set_bit(0, &fdc_busy)))
+		return -EINTR;
 
-		set_current_state(TASK_RUNNING);
-		remove_wait_queue(&fdc_wait, &wait);
-		flush_scheduled_work();
-	}
 	command_status = FD_COMMAND_NONE;
 
 	__reschedule_timeout(drive, "lock fdc");
@@ -895,9 +872,6 @@ static int _lock_fdc(int drive, bool int
 	return 0;
 }
 
-#define lock_fdc(drive, interruptible)			\
-	_lock_fdc(drive, interruptible, __LINE__)
-
 /* unlocks the driver */
 static void unlock_fdc(void)
 {
@@ -2015,25 +1989,10 @@ static int wait_til_done(void (*handler)
 
 	schedule_bh(handler);
 
-	if (command_status < 2 && NO_SIGNAL) {
-		DECLARE_WAITQUEUE(wait, current);
-
-		add_wait_queue(&command_done, &wait);
-		for (;;) {
-			set_current_state(interruptible ?
-					  TASK_INTERRUPTIBLE :
-					  TASK_UNINTERRUPTIBLE);
-
-			if (command_status >= 2 || !NO_SIGNAL)
-				break;
-
-			is_alive(__func__, "");
-			schedule();
-		}
-
-		set_current_state(TASK_RUNNING);
-		remove_wait_queue(&command_done, &wait);
-	}
+	if (interruptible)
+		wait_event_interruptible(command_done, command_status >= 2);
+	else
+		wait_event(command_done, command_status >= 2);
 
 	if (command_status < 2) {
 		cancel_activity();



  parent reply	other threads:[~2010-06-09 18:54 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-09 18:34 [PATCH 0/8] floppy: cleanup patches Stephen Hemminger
2010-06-09 18:34 ` [PATCH 1/8] floppy: initialize debug jiffies offset Stephen Hemminger
2010-06-09 18:34 ` [PATCH 2/8] floppy: remove unnecessary inlines Stephen Hemminger
2010-06-09 18:34 ` [PATCH 3/8] floppy: silence warning during disk test Stephen Hemminger
2010-06-09 18:34 ` [PATCH 4/8] floppy: use atomic type for usage_count Stephen Hemminger
2010-06-09 18:34 ` [PATCH 5/8] floppy: cmos attribute should be static Stephen Hemminger
2010-06-09 18:34 ` [PATCH 6/8] floppy: fix signed/unsigned warnings Stephen Hemminger
2010-06-09 18:34 ` Stephen Hemminger [this message]
2010-06-09 18:34 ` [PATCH 8/8] floppy: use warning macros Stephen Hemminger
2010-06-09 18:46 ` [PATCH 0/8] floppy: cleanup patches Linus Torvalds
2010-06-09 18:54   ` Stephen Hemminger
2010-06-09 19:04     ` Linus Torvalds
2010-06-11 17:32       ` [RFC] floppy: use single threaded workqueue Stephen Hemminger
2010-06-11 18:56         ` Linus Torvalds
2010-07-21 19:55         ` Marcelo Tosatti
2010-07-22 19:09           ` Linus Torvalds
2010-07-22 22:22             ` david
2010-07-22 23:00               ` Linus Torvalds
2010-08-22  9:07               ` Amos Kong
2010-08-23 22:22                 ` Stephen Hemminger
2010-06-10  6:43 ` [PATCH 0/8] floppy: cleanup patches Thomas Meyer
2010-06-11 17:30   ` Stephen Hemminger
2010-06-13 17:23     ` Thomas Meyer

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=20100609183626.205751245@vyatta.com \
    --to=shemminger@vyatta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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