Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 106fd892 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Jens Axboe
Browse files

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: default avatarArnd Bergmann <arnd@arndb.de>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 7b8a3d22
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -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,15 +841,18 @@ 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) {
			spin_unlock_irqrestore(&swim3_lock, flags);
			if (interruptible && signal_pending(current)) {
		/* 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);
			return -EINTR;
		}
			interruptible_sleep_on(&fs->wait);
			spin_lock_irqsave(&swim3_lock, flags);
		}
		--fs->wanted;
	}
	fs->state = state;