diff options
author | Arnd Bergmann <arnd@arndb.de> | 2014-02-26 11:01:44 (GMT) |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2014-03-13 20:56:38 (GMT) |
commit | 106fd892bc714a9b7c28daba98a3623a41c32f1a (patch) | |
tree | aaa08a49fe4c4bcb6ae342649cde84cbd879521e /drivers/block/swim3.c | |
parent | 7b8a3d22ba93682a542a445ef43d03f495cdf3d6 (diff) | |
download | linux-106fd892bc714a9b7c28daba98a3623a41c32f1a.tar.xz |
swim3: fix interruptible_sleep_on race
interruptible_sleep_on is racy and going away. This replaces the one
caller in the swim3 driver with the equivalent race-free
wait_event_interruptible call. Since we're here already, this
also fixes the case where we get interrupted from atomic context,
which used to just spin in the loop.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'drivers/block/swim3.c')
-rw-r--r-- | drivers/block/swim3.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c index 20e061c..c74f7b5 100644 --- a/drivers/block/swim3.c +++ b/drivers/block/swim3.c @@ -30,6 +30,7 @@ #include <linux/mutex.h> #include <linux/module.h> #include <linux/spinlock.h> +#include <linux/wait.h> #include <asm/io.h> #include <asm/dbdma.h> #include <asm/prom.h> @@ -840,14 +841,17 @@ static int grab_drive(struct floppy_state *fs, enum swim_state state, spin_lock_irqsave(&swim3_lock, flags); if (fs->state != idle && fs->state != available) { ++fs->wanted; - while (fs->state != available) { + /* this will enable irqs in order to sleep */ + if (!interruptible) + wait_event_lock_irq(fs->wait, + fs->state == available, + swim3_lock); + else if (wait_event_interruptible_lock_irq(fs->wait, + fs->state == available, + swim3_lock)) { + --fs->wanted; spin_unlock_irqrestore(&swim3_lock, flags); - if (interruptible && signal_pending(current)) { - --fs->wanted; - return -EINTR; - } - interruptible_sleep_on(&fs->wait); - spin_lock_irqsave(&swim3_lock, flags); + return -EINTR; } --fs->wanted; } |