]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/block/floppy.c
floppy: use wait_event_interruptible
[net-next-2.6.git] / drivers / block / floppy.c
index 7ba239e8f0dc7b6d052eed3b9790eec0106d7aef..3fdceda8573548969d40df3d1b3ed8801a027279 100644 (file)
@@ -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;
 
@@ -578,7 +576,7 @@ static void reset_fdc(void);
 #define NEED_1_RECAL   -2
 #define NEED_2_RECAL   -3
 
-static int usage_count;
+static atomic_t usage_count = ATOMIC_INIT(0);
 
 /* buffer related variables */
 static int buffer_track = -1;
@@ -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 (!usage_count) {
-               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 interruptible, int line)
        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)(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();
@@ -2941,7 +2900,7 @@ static void do_fd_request(struct request_queue *q)
                return;
        }
 
-       if (usage_count == 0) {
+       if (atomic_read(&usage_count) == 0) {
                pr_info("warning: usage count=0, current_req=%p exiting\n",
                        current_req);
                pr_info("sect=%ld type=%x flags=%x\n",
@@ -3337,7 +3296,7 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g,
 }
 
 /* handle obsolete ioctl's */
-static int ioctl_table[] = {
+static unsigned int ioctl_table[] = {
        FDCLRPRM,
        FDSETPRM,
        FDDEFPRM,
@@ -3365,7 +3324,7 @@ static int ioctl_table[] = {
        FDTWADDLE
 };
 
-static int normalize_ioctl(int *cmd, int *size)
+static int normalize_ioctl(unsigned int *cmd, int *size)
 {
        int i;
 
@@ -3829,6 +3788,7 @@ static int __floppy_read_block_0(struct block_device *bdev)
        bio.bi_size = size;
        bio.bi_bdev = bdev;
        bio.bi_sector = 0;
+       bio.bi_flags = BIO_QUIET;
        init_completion(&complete);
        bio.bi_private = &complete;
        bio.bi_end_io = floppy_rb0_complete;
@@ -3857,7 +3817,7 @@ static int floppy_revalidate(struct gendisk *disk)
        if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
            test_bit(FD_VERIFY_BIT, &UDRS->flags) ||
            test_bit(drive, &fake_change) || NO_GEOM) {
-               if (usage_count == 0) {
+               if (atomic_read(&usage_count) == 0) {
                        pr_info("VFS: revalidate called on non-open device.\n");
                        return -EFAULT;
                }
@@ -4126,7 +4086,7 @@ static ssize_t floppy_cmos_show(struct device *dev,
        return sprintf(buf, "%X\n", UDP->cmos);
 }
 
-DEVICE_ATTR(cmos, S_IRUGO, floppy_cmos_show, NULL);
+static DEVICE_ATTR(cmos, S_IRUGO, floppy_cmos_show, NULL);
 
 static void floppy_device_release(struct device *dev)
 {
@@ -4356,7 +4316,7 @@ out_unreg_platform_dev:
        platform_device_unregister(&floppy_device[drive]);
 out_flush_work:
        flush_scheduled_work();
-       if (usage_count)
+       if (atomic_read(&usage_count))
                floppy_release_irq_and_dma();
 out_unreg_region:
        blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256);
@@ -4373,8 +4333,6 @@ out_put_disk:
        return err;
 }
 
-static DEFINE_SPINLOCK(floppy_usage_lock);
-
 static const struct io_region {
        int offset;
        int size;
@@ -4420,14 +4378,8 @@ static void floppy_release_regions(int fdc)
 
 static int floppy_grab_irq_and_dma(void)
 {
-       unsigned long flags;
-
-       spin_lock_irqsave(&floppy_usage_lock, flags);
-       if (usage_count++) {
-               spin_unlock_irqrestore(&floppy_usage_lock, flags);
+       if (atomic_inc_return(&usage_count) > 1)
                return 0;
-       }
-       spin_unlock_irqrestore(&floppy_usage_lock, flags);
 
        /*
         * We might have scheduled a free_irq(), wait it to
@@ -4438,9 +4390,7 @@ static int floppy_grab_irq_and_dma(void)
        if (fd_request_irq()) {
                DPRINT("Unable to grab IRQ%d for the floppy driver\n",
                       FLOPPY_IRQ);
-               spin_lock_irqsave(&floppy_usage_lock, flags);
-               usage_count--;
-               spin_unlock_irqrestore(&floppy_usage_lock, flags);
+               atomic_dec(&usage_count);
                return -1;
        }
        if (fd_request_dma()) {
@@ -4450,9 +4400,7 @@ static int floppy_grab_irq_and_dma(void)
                        use_virtual_dma = can_use_virtual_dma = 1;
                if (!(can_use_virtual_dma & 1)) {
                        fd_free_irq();
-                       spin_lock_irqsave(&floppy_usage_lock, flags);
-                       usage_count--;
-                       spin_unlock_irqrestore(&floppy_usage_lock, flags);
+                       atomic_dec(&usage_count);
                        return -1;
                }
        }
@@ -4487,9 +4435,7 @@ cleanup:
        fd_free_dma();
        while (--fdc >= 0)
                floppy_release_regions(fdc);
-       spin_lock_irqsave(&floppy_usage_lock, flags);
-       usage_count--;
-       spin_unlock_irqrestore(&floppy_usage_lock, flags);
+       atomic_dec(&usage_count);
        return -1;
 }
 
@@ -4501,14 +4447,10 @@ static void floppy_release_irq_and_dma(void)
 #endif
        long tmpsize;
        unsigned long tmpaddr;
-       unsigned long flags;
 
-       spin_lock_irqsave(&floppy_usage_lock, flags);
-       if (--usage_count) {
-               spin_unlock_irqrestore(&floppy_usage_lock, flags);
+       if (!atomic_dec_and_test(&usage_count))
                return;
-       }
-       spin_unlock_irqrestore(&floppy_usage_lock, flags);
+
        if (irqdma_allocated) {
                fd_disable_dma();
                fd_free_dma();
@@ -4601,7 +4543,7 @@ static void __exit floppy_module_exit(void)
        del_timer_sync(&fd_timer);
        blk_cleanup_queue(floppy_queue);
 
-       if (usage_count)
+       if (atomic_read(&usage_count))
                floppy_release_irq_and_dma();
 
        /* eject disk, if any */