Skip to content

Commit

Permalink
floppy: use wait_event_interruptible
Browse files Browse the repository at this point in the history
Convert wait loops to use wait_event_ macros.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
  • Loading branch information
Stephen Hemminger authored and Jens Axboe committed Aug 7, 2010
1 parent 21af544 commit b862f26
Showing 1 changed file with 9 additions and 50 deletions.
59 changes: 9 additions & 50 deletions drivers/block/floppy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -858,46 +856,22 @@ 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");
set_fdc(drive);
return 0;
}

#define lock_fdc(drive, interruptible) \
_lock_fdc(drive, interruptible, __LINE__)

/* unlocks the driver */
static void unlock_fdc(void)
{
Expand Down Expand Up @@ -2015,25 +1989,10 @@ static int wait_til_done(void (*handler)(void), bool interruptible)

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();
Expand Down

0 comments on commit b862f26

Please sign in to comment.