drm/nv50: fix iommu errors caused by device reading from address 0
[safe/jmp/linux-2.6] / drivers / block / floppy.c
index 50bd9e9..90c4038 100644 (file)
  * Better audit of register_blkdev.
  */
 
-#define FLOPPY_SANITY_CHECK
 #undef  FLOPPY_SILENT_DCL_CLEAR
 
 #define REALLY_SLOW_IO
 
 #define DEBUGT 2
+
+#define DPRINT(format, args...) \
+       pr_info("floppy%d: " format, current_drive, ##args)
+
 #define DCL_DEBUG              /* debug disk change line */
+#ifdef DCL_DEBUG
+#define debug_dcl(test, fmt, args...) \
+       do { if ((test) & FD_DEBUG) DPRINT(fmt, ##args); } while (0)
+#else
+#define debug_dcl(test, fmt, args...) \
+       do { if (0) DPRINT(fmt, ##args); } while (0)
+#endif
 
 /* do print messages for unexpected interrupts */
 static int print_unex = 1;
@@ -241,8 +251,6 @@ static int allowed_drive_mask = 0x33;
 
 static int irqdma_allocated;
 
-#define DEVICE_NAME "floppy"
-
 #include <linux/blkdev.h>
 #include <linux/blkpg.h>
 #include <linux/cdrom.h>       /* for the compatibility eject ioctl */
@@ -283,7 +291,7 @@ static inline void fallback_on_nodma_alloc(char **addr, size_t l)
 /* End dma memory related stuff */
 
 static unsigned long fake_change;
-static int initialising = 1;
+static bool initialized;
 
 #define ITYPE(x)       (((x) >> 2) & 0x1f)
 #define TOMINOR(x)     ((x & 3) | ((x & 4) << 5))
@@ -296,20 +304,11 @@ static int initialising = 1;
 #define DRS    (&drive_state[current_drive])
 #define DRWE   (&write_errors[current_drive])
 #define FDCS   (&fdc_state[fdc])
-#define CLEARF(x)      clear_bit(x##_BIT, &DRS->flags)
-#define SETF(x)                set_bit(x##_BIT, &DRS->flags)
-#define TESTF(x)       test_bit(x##_BIT, &DRS->flags)
 
 #define UDP    (&drive_params[drive])
 #define UDRS   (&drive_state[drive])
 #define UDRWE  (&write_errors[drive])
 #define UFDCS  (&fdc_state[FDC(drive)])
-#define UCLEARF(x)     clear_bit(x##_BIT, &UDRS->flags)
-#define USETF(x)       set_bit(x##_BIT, &UDRS->flags)
-#define UTESTF(x)      test_bit(x##_BIT, &UDRS->flags)
-
-#define DPRINT(format, args...) \
-       pr_info(DEVICE_NAME "%d: " format, current_drive, ##args)
 
 #define PH_HEAD(floppy, head) (((((floppy)->stretch & 2) >> 1) ^ head) << 2)
 #define STRETCH(floppy)        ((floppy)->stretch & FD_STRETCH)
@@ -345,7 +344,7 @@ static int initialising = 1;
  */
 #define MAX_REPLIES 16
 static unsigned char reply_buffer[MAX_REPLIES];
-static int inr;                        /* size of reply buffer, when called from interrupt */
+static int inr;                /* size of reply buffer, when called from interrupt */
 #define ST0            (reply_buffer[0])
 #define ST1            (reply_buffer[1])
 #define ST2            (reply_buffer[2])
@@ -516,11 +515,6 @@ static DECLARE_WAIT_QUEUE_HEAD(fdc_wait);
 static DECLARE_WAIT_QUEUE_HEAD(command_done);
 
 #define NO_SIGNAL (!interruptible || !signal_pending(current))
-#define CALL(x)                if ((x) == -EINTR) return -EINTR
-#define ECALL(x)       if ((ret = (x))) return ret;
-#define _WAIT(x,i)     CALL(ret=wait_til_done((x),i))
-#define WAIT(x)                _WAIT((x),interruptible)
-#define IWAIT(x)       _WAIT((x),1)
 
 /* Errors during formatting are counted here. */
 static int format_errors;
@@ -622,14 +616,14 @@ static inline void set_debugt(void)
        debugtimer = jiffies;
 }
 
-static inline void debugt(const char *message)
+static inline void debugt(const char *func, const char *msg)
 {
        if (DP->flags & DEBUGT)
-               pr_info("%s dtime=%lu\n", message, jiffies - debugtimer);
+               pr_info("%s:%s dtime=%lu\n", func, msg, jiffies - debugtimer);
 }
 #else
 static inline void set_debugt(void) { }
-static inline void debugt(const char *message) { }
+static inline void debugt(const char *func, const char *msg) { }
 #endif /* DEBUGT */
 
 typedef void (*timeout_fn)(unsigned long);
@@ -637,21 +631,17 @@ static DEFINE_TIMER(fd_timeout, floppy_shutdown, 0, 0);
 
 static const char *timeout_message;
 
-#ifdef FLOPPY_SANITY_CHECK
-static void is_alive(const char *message)
+static void is_alive(const char *func, const char *message)
 {
        /* this routine checks whether the floppy driver is "alive" */
-       if (test_bit(0, &fdc_busy) && command_status < 2
-           && !timer_pending(&fd_timeout)) {
-               DPRINT("timeout handler died: %s\n", message);
+       if (test_bit(0, &fdc_busy) && command_status < 2 &&
+           !timer_pending(&fd_timeout)) {
+               DPRINT("%s: timeout handler died.  %s\n", func, message);
        }
 }
-#endif
 
 static void (*do_floppy)(void) = NULL;
 
-#ifdef FLOPPY_SANITY_CHECK
-
 #define OLOGSIZE 20
 
 static void (*lasthandler)(void);
@@ -667,12 +657,11 @@ static struct output_log {
 } output_log[OLOGSIZE];
 
 static int output_log_pos;
-#endif
 
 #define current_reqD -1
 #define MAXTIMEOUT -2
 
-static void __reschedule_timeout(int drive, const char *message, int marg)
+static void __reschedule_timeout(int drive, const char *message)
 {
        if (drive == current_reqD)
                drive = current_drive;
@@ -684,16 +673,16 @@ static void __reschedule_timeout(int drive, const char *message, int marg)
                fd_timeout.expires = jiffies + UDP->timeout;
        add_timer(&fd_timeout);
        if (UDP->flags & FD_DEBUG)
-               DPRINT("reschedule timeout %s %d\n", message, marg);
+               DPRINT("reschedule timeout %s\n", message);
        timeout_message = message;
 }
 
-static void reschedule_timeout(int drive, const char *message, int marg)
+static void reschedule_timeout(int drive, const char *message)
 {
        unsigned long flags;
 
        spin_lock_irqsave(&floppy_lock, flags);
-       __reschedule_timeout(drive, message, marg);
+       __reschedule_timeout(drive, message);
        spin_unlock_irqrestore(&floppy_lock, flags);
 }
 
@@ -737,7 +726,6 @@ static int disk_change(int drive)
 {
        int fdc = FDC(drive);
 
-#ifdef FLOPPY_SANITY_CHECK
        if (time_before(jiffies, UDRS->select_date + UDP->select_delay))
                DPRINT("WARNING disk change called early\n");
        if (!(FDCS->dor & (0x10 << UNIT(drive))) ||
@@ -746,31 +734,27 @@ static int disk_change(int drive)
                DPRINT("drive=%d fdc=%d dor=%x\n", drive, FDC(drive),
                       (unsigned int)FDCS->dor);
        }
-#endif
 
-#ifdef DCL_DEBUG
-       if (UDP->flags & FD_DEBUG) {
-               DPRINT("checking disk change line for drive %d\n", drive);
-               DPRINT("jiffies=%lu\n", jiffies);
-               DPRINT("disk change line=%x\n", fd_inb(FD_DIR) & 0x80);
-               DPRINT("flags=%lx\n", UDRS->flags);
-       }
-#endif
+       debug_dcl(UDP->flags,
+                 "checking disk change line for drive %d\n", drive);
+       debug_dcl(UDP->flags, "jiffies=%lu\n", jiffies);
+       debug_dcl(UDP->flags, "disk change line=%x\n", fd_inb(FD_DIR) & 0x80);
+       debug_dcl(UDP->flags, "flags=%lx\n", UDRS->flags);
+
        if (UDP->flags & FD_BROKEN_DCL)
-               return UTESTF(FD_DISK_CHANGED);
+               return test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
        if ((fd_inb(FD_DIR) ^ UDP->flags) & 0x80) {
-               USETF(FD_VERIFY);       /* verify write protection */
-               if (UDRS->maxblock) {
-                       /* mark it changed */
-                       USETF(FD_DISK_CHANGED);
-               }
+               set_bit(FD_VERIFY_BIT, &UDRS->flags);
+                                       /* verify write protection */
+
+               if (UDRS->maxblock)     /* mark it changed */
+                       set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
 
                /* invalidate its geometry */
                if (UDRS->keep_data >= 0) {
                        if ((UDP->flags & FTD_MSG) &&
                            current_type[drive] != NULL)
-                               DPRINT("Disk type is undefined after "
-                                      "disk change\n");
+                               DPRINT("Disk type is undefined after disk change\n");
                        current_type[drive] = NULL;
                        floppy_sizes[TOMINOR(drive)] = MAX_DISK_SIZE << 1;
                }
@@ -778,7 +762,7 @@ static int disk_change(int drive)
                return 1;
        } else {
                UDRS->last_checked = jiffies;
-               UCLEARF(FD_DISK_NEWCHANGE);
+               clear_bit(FD_DISK_NEWCHANGE_BIT, &UDRS->flags);
        }
        return 0;
 }
@@ -788,6 +772,12 @@ static inline int is_selected(int dor, int unit)
        return ((dor & (0x10 << unit)) && (dor & 3) == unit);
 }
 
+static bool is_ready_state(int status)
+{
+       int state = status & (STATUS_READY | STATUS_DIR | STATUS_DMA);
+       return state == STATUS_READY;
+}
+
 static int set_dor(int fdc, char mask, char data)
 {
        unsigned char unit;
@@ -804,10 +794,8 @@ static int set_dor(int fdc, char mask, char data)
                unit = olddor & 0x3;
                if (is_selected(olddor, unit) && !is_selected(newdor, unit)) {
                        drive = REVDRIVE(fdc, unit);
-#ifdef DCL_DEBUG
-                       if (UDP->flags & FD_DEBUG)
-                               DPRINT("calling disk change from set_dor\n");
-#endif
+                       debug_dcl(UDP->flags,
+                                 "calling disk change from set_dor\n");
                        disk_change(drive);
                }
                FDCS->dor = newdor;
@@ -831,8 +819,10 @@ static void twaddle(void)
        DRS->select_date = jiffies;
 }
 
-/* reset all driver information about the current fdc. This is needed after
- * a reset, and after a raw command. */
+/*
+ * Reset all driver information about the current fdc.
+ * This is needed after a reset, and after a raw command.
+ */
 static void reset_fdc_info(int mode)
 {
        int drive;
@@ -868,7 +858,7 @@ static void set_fdc(int drive)
 }
 
 /* locks the driver */
-static int _lock_fdc(int drive, int interruptible, int line)
+static int _lock_fdc(int drive, bool interruptible, int line)
 {
        if (!usage_count) {
                pr_err("Trying to lock fdc while usage count=0 at line %d\n",
@@ -900,7 +890,7 @@ static int _lock_fdc(int drive, int interruptible, int line)
        }
        command_status = FD_COMMAND_NONE;
 
-       __reschedule_timeout(drive, "lock fdc", 0);
+       __reschedule_timeout(drive, "lock fdc");
        set_fdc(drive);
        return 0;
 }
@@ -918,7 +908,7 @@ static inline void unlock_fdc(void)
                DPRINT("FDC access conflict!\n");
 
        if (do_floppy)
-               DPRINT("device interrupt still active at FDC release: %p!\n",
+               DPRINT("device interrupt still active at FDC release: %pf!\n",
                       do_floppy);
        command_status = FD_COMMAND_NONE;
        spin_lock_irqsave(&floppy_lock, flags);
@@ -1020,10 +1010,7 @@ static void cancel_activity(void)
  * transfer */
 static void fd_watchdog(void)
 {
-#ifdef DCL_DEBUG
-       if (DP->flags & FD_DEBUG)
-               DPRINT("calling disk change from watchdog\n");
-#endif
+       debug_dcl(DP->flags, "calling disk change from watchdog\n");
 
        if (disk_change(current_drive)) {
                DPRINT("disk removed during i/o\n");
@@ -1098,7 +1085,6 @@ static void setup_DMA(void)
 {
        unsigned long f;
 
-#ifdef FLOPPY_SANITY_CHECK
        if (raw_cmd->length == 0) {
                int i;
 
@@ -1116,7 +1102,6 @@ static void setup_DMA(void)
                FDCS->reset = 1;
                return;
        }
-#endif
        f = claim_dma_lock();
        fd_disable_dma();
 #ifdef fd_dma_setup
@@ -1158,7 +1143,7 @@ static int wait_til_ready(void)
                if (status & STATUS_READY)
                        return status;
        }
-       if (!initialising) {
+       if (initialized) {
                DPRINT("Getstatus times out (%x) on fdc %d\n", status, fdc);
                show_floppy();
        }
@@ -1173,18 +1158,17 @@ static int output_byte(char byte)
 
        if (status < 0)
                return -1;
-       if ((status & (STATUS_READY | STATUS_DIR | STATUS_DMA)) == STATUS_READY) {
+
+       if (is_ready_state(status)) {
                fd_outb(byte, FD_DATA);
-#ifdef FLOPPY_SANITY_CHECK
                output_log[output_log_pos].data = byte;
                output_log[output_log_pos].status = status;
                output_log[output_log_pos].jiffies = jiffies;
                output_log_pos = (output_log_pos + 1) % OLOGSIZE;
-#endif
                return 0;
        }
        FDCS->reset = 1;
-       if (!initialising) {
+       if (initialized) {
                DPRINT("Unable to send byte %x to FDC. Fdc=%x Status=%x\n",
                       byte, fdc, status);
                show_floppy();
@@ -1204,10 +1188,8 @@ static int result(void)
                        break;
                status &= STATUS_DIR | STATUS_READY | STATUS_BUSY | STATUS_DMA;
                if ((status & ~STATUS_BUSY) == STATUS_READY) {
-#ifdef FLOPPY_SANITY_CHECK
                        resultjiffies = jiffies;
                        resultsize = i;
-#endif
                        return i;
                }
                if (status == (STATUS_DIR | STATUS_READY | STATUS_BUSY))
@@ -1215,10 +1197,9 @@ static int result(void)
                else
                        break;
        }
-       if (!initialising) {
-               DPRINT
-                   ("get result error. Fdc=%d Last status=%x Read bytes=%d\n",
-                    fdc, status, i);
+       if (initialized) {
+               DPRINT("get result error. Fdc=%d Last status=%x Read bytes=%d\n",
+                      fdc, status, i);
                show_floppy();
        }
        FDCS->reset = 1;
@@ -1233,8 +1214,10 @@ static int need_more_output(void)
 
        if (status < 0)
                return -1;
-       if ((status & (STATUS_READY | STATUS_DIR | STATUS_DMA)) == STATUS_READY)
+
+       if (is_ready_state(status))
                return MORE_OUTPUT;
+
        return result();
 }
 
@@ -1462,7 +1445,7 @@ static int interpret_errors(void)
        char bad;
 
        if (inr != 7) {
-               DPRINT("-- FDC reply error");
+               DPRINT("-- FDC reply error\n");
                FDCS->reset = 1;
                return 1;
        }
@@ -1475,11 +1458,11 @@ static int interpret_errors(void)
                bad = 1;
                if (ST1 & ST1_WP) {
                        DPRINT("Drive is write protected\n");
-                       CLEARF(FD_DISK_WRITABLE);
+                       clear_bit(FD_DISK_WRITABLE_BIT, &DRS->flags);
                        cont->done(0);
                        bad = 2;
                } else if (ST1 & ST1_ND) {
-                       SETF(FD_NEED_TWADDLE);
+                       set_bit(FD_NEED_TWADDLE_BIT, &DRS->flags);
                } else if (ST1 & ST1_OR) {
                        if (DP->flags & FTD_MSG)
                                DPRINT("Over/Underrun - retrying\n");
@@ -1550,7 +1533,7 @@ static void setup_rw_floppy(void)
        for (i = 0; i < raw_cmd->cmd_count; i++)
                r |= output_byte(raw_cmd->cmd[i]);
 
-       debugt("rw_command: ");
+       debugt(__func__, "rw_command");
 
        if (r) {
                cont->error();
@@ -1573,7 +1556,7 @@ static int blind_seek;
  */
 static void seek_interrupt(void)
 {
-       debugt("seek interrupt:");
+       debugt(__func__, "");
        if (inr != 2 || (ST0 & 0xF8) != 0x20) {
                DPRINT("seek failed\n");
                DRS->track = NEED_2_RECAL;
@@ -1582,13 +1565,11 @@ static void seek_interrupt(void)
                return;
        }
        if (DRS->track >= 0 && DRS->track != ST1 && !blind_seek) {
-#ifdef DCL_DEBUG
-               if (DP->flags & FD_DEBUG) {
-                       DPRINT("clearing NEWCHANGE flag because of effective seek\n");
-                       DPRINT("jiffies=%lu\n", jiffies);
-               }
-#endif
-               CLEARF(FD_DISK_NEWCHANGE);      /* effective seek */
+               debug_dcl(DP->flags,
+                         "clearing NEWCHANGE flag because of effective seek\n");
+               debug_dcl(DP->flags, "jiffies=%lu\n", jiffies);
+               clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
+                                       /* effective seek */
                DRS->select_date = jiffies;
        }
        DRS->track = ST1;
@@ -1597,26 +1578,23 @@ static void seek_interrupt(void)
 
 static void check_wp(void)
 {
-       if (TESTF(FD_VERIFY)) {
-               /* check write protection */
+       if (test_bit(FD_VERIFY_BIT, &DRS->flags)) {
+                                       /* check write protection */
                output_byte(FD_GETSTATUS);
                output_byte(UNIT(current_drive));
                if (result() != 1) {
                        FDCS->reset = 1;
                        return;
                }
-               CLEARF(FD_VERIFY);
-               CLEARF(FD_NEED_TWADDLE);
-#ifdef DCL_DEBUG
-               if (DP->flags & FD_DEBUG) {
-                       DPRINT("checking whether disk is write protected\n");
-                       DPRINT("wp=%x\n", ST3 & 0x40);
-               }
-#endif
+               clear_bit(FD_VERIFY_BIT, &DRS->flags);
+               clear_bit(FD_NEED_TWADDLE_BIT, &DRS->flags);
+               debug_dcl(DP->flags,
+                         "checking whether disk is write protected\n");
+               debug_dcl(DP->flags, "wp=%x\n", ST3 & 0x40);
                if (!(ST3 & 0x40))
-                       SETF(FD_DISK_WRITABLE);
+                       set_bit(FD_DISK_WRITABLE_BIT, &DRS->flags);
                else
-                       CLEARF(FD_DISK_WRITABLE);
+                       clear_bit(FD_DISK_WRITABLE_BIT, &DRS->flags);
        }
 }
 
@@ -1626,18 +1604,15 @@ static void seek_floppy(void)
 
        blind_seek = 0;
 
-#ifdef DCL_DEBUG
-       if (DP->flags & FD_DEBUG)
-               DPRINT("calling disk change from seek\n");
-#endif
+       debug_dcl(DP->flags, "calling disk change from %s\n", __func__);
 
-       if (!TESTF(FD_DISK_NEWCHANGE) &&
+       if (!test_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags) &&
            disk_change(current_drive) && (raw_cmd->flags & FD_RAW_NEED_DISK)) {
                /* the media changed flag should be cleared after the seek.
                 * If it isn't, this means that there is really no disk in
                 * the drive.
                 */
-               SETF(FD_DISK_CHANGED);
+               set_bit(FD_DISK_CHANGED_BIT, &DRS->flags);
                cont->done(0);
                cont->redo();
                return;
@@ -1645,7 +1620,7 @@ static void seek_floppy(void)
        if (DRS->track <= NEED_1_RECAL) {
                recalibrate_floppy();
                return;
-       } else if (TESTF(FD_DISK_NEWCHANGE) &&
+       } else if (test_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags) &&
                   (raw_cmd->flags & FD_RAW_NEED_DISK) &&
                   (DRS->track <= NO_TRACK || DRS->track == raw_cmd->track)) {
                /* we seek to clear the media-changed condition. Does anybody
@@ -1678,18 +1653,18 @@ static void seek_floppy(void)
                reset_fdc();
                return;
        }
-       debugt("seek command:");
+       debugt(__func__, "");
 }
 
 static void recal_interrupt(void)
 {
-       debugt("recal interrupt:");
+       debugt(__func__, "");
        if (inr != 2)
                FDCS->reset = 1;
        else if (ST0 & ST0_ECE) {
                switch (DRS->track) {
                case NEED_1_RECAL:
-                       debugt("recal interrupt need 1 recal:");
+                       debugt(__func__, "need 1 recal");
                        /* after a second recalibrate, we still haven't
                         * reached track 0. Probably no drive. Raise an
                         * error, as failing immediately might upset
@@ -1698,23 +1673,21 @@ static void recal_interrupt(void)
                        cont->redo();
                        return;
                case NEED_2_RECAL:
-                       debugt("recal interrupt need 2 recal:");
+                       debugt(__func__, "need 2 recal");
                        /* If we already did a recalibrate,
                         * and we are not at track 0, this
                         * means we have moved. (The only way
                         * not to move at recalibration is to
                         * be already at track 0.) Clear the
                         * new change flag */
-#ifdef DCL_DEBUG
-                       if (DP->flags & FD_DEBUG)
-                               DPRINT("clearing NEWCHANGE flag because of second recalibrate\n");
-#endif
+                       debug_dcl(DP->flags,
+                                 "clearing NEWCHANGE flag because of second recalibrate\n");
 
-                       CLEARF(FD_DISK_NEWCHANGE);
+                       clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
                        DRS->select_date = jiffies;
                        /* fall through */
                default:
-                       debugt("recal interrupt default:");
+                       debugt(__func__, "default");
                        /* Recalibrate moves the head by at
                         * most 80 steps. If after one
                         * recalibrate we don't have reached
@@ -1760,8 +1733,8 @@ irqreturn_t floppy_interrupt(int irq, void *dev_id)
                /* we don't even know which FDC is the culprit */
                pr_info("DOR0=%x\n", fdc_state[0].dor);
                pr_info("floppy interrupt on bizarre fdc %d\n", fdc);
-               pr_info("handler=%p\n", handler);
-               is_alive("bizarre fdc");
+               pr_info("handler=%pf\n", handler);
+               is_alive(__func__, "bizarre fdc");
                return IRQ_NONE;
        }
 
@@ -1775,7 +1748,7 @@ irqreturn_t floppy_interrupt(int irq, void *dev_id)
         * activity.
         */
 
-       do_print = !handler && print_unex && !initialising;
+       do_print = !handler && print_unex && initialized;
 
        inr = result();
        if (do_print)
@@ -1788,15 +1761,15 @@ irqreturn_t floppy_interrupt(int irq, void *dev_id)
                        if (do_print)
                                print_result("sensei", inr);
                        max_sensei--;
-               } while ((ST0 & 0x83) != UNIT(current_drive) && inr == 2
-                        && max_sensei);
+               } while ((ST0 & 0x83) != UNIT(current_drive) &&
+                        inr == 2 && max_sensei);
        }
        if (!handler) {
                FDCS->reset = 1;
                return IRQ_NONE;
        }
        schedule_bh(handler);
-       is_alive("normal interrupt end");
+       is_alive(__func__, "normal interrupt end");
 
        /* FIXME! Was it really for us? */
        return IRQ_HANDLED;
@@ -1804,13 +1777,11 @@ irqreturn_t floppy_interrupt(int irq, void *dev_id)
 
 static void recalibrate_floppy(void)
 {
-       debugt("recalibrate floppy:");
+       debugt(__func__, "");
        do_floppy = recal_interrupt;
        output_byte(FD_RECALIBRATE);
-       if (output_byte(UNIT(current_drive)) < 0) {
+       if (output_byte(UNIT(current_drive)) < 0)
                reset_fdc();
-               return;
-       }
 }
 
 /*
@@ -1818,10 +1789,10 @@ static void recalibrate_floppy(void)
  */
 static void reset_interrupt(void)
 {
-       debugt("reset interrupt:");
+       debugt(__func__, "");
        result();               /* get the status ready for set_fdc */
        if (FDCS->reset) {
-               pr_info("reset set in interrupt, calling %p\n", cont->error);
+               pr_info("reset set in interrupt, calling %pf\n", cont->error);
                cont->error();  /* a reset just after a reset. BAD! */
        }
        cont->redo();
@@ -1862,11 +1833,10 @@ static void show_floppy(void)
        pr_info("\n");
        pr_info("floppy driver state\n");
        pr_info("-------------------\n");
-       pr_info("now=%lu last interrupt=%lu diff=%lu last called handler=%p\n",
+       pr_info("now=%lu last interrupt=%lu diff=%lu last called handler=%pf\n",
                jiffies, interruptjiffies, jiffies - interruptjiffies,
                lasthandler);
 
-#ifdef FLOPPY_SANITY_CHECK
        pr_info("timeout_message=%s\n", timeout_message);
        pr_info("last output bytes:\n");
        for (i = 0; i < OLOGSIZE; i++)
@@ -1878,18 +1848,17 @@ static void show_floppy(void)
        pr_info("last redo_fd_request at %lu\n", lastredo);
        print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1,
                       reply_buffer, resultsize, true);
-#endif
 
        pr_info("status=%x\n", fd_inb(FD_STATUS));
        pr_info("fdc_busy=%lu\n", fdc_busy);
        if (do_floppy)
-               pr_info("do_floppy=%p\n", do_floppy);
+               pr_info("do_floppy=%pf\n", do_floppy);
        if (work_pending(&floppy_work))
-               pr_info("floppy_work.func=%p\n", floppy_work.func);
+               pr_info("floppy_work.func=%pf\n", floppy_work.func);
        if (timer_pending(&fd_timer))
-               pr_info("fd_timer.function=%p\n", fd_timer.function);
+               pr_info("fd_timer.function=%pf\n", fd_timer.function);
        if (timer_pending(&fd_timeout)) {
-               pr_info("timer_function=%p\n", fd_timeout.function);
+               pr_info("timer_function=%pf\n", fd_timeout.function);
                pr_info("expires=%lu\n", fd_timeout.expires - jiffies);
                pr_info("now=%lu\n", jiffies);
        }
@@ -1903,7 +1872,7 @@ static void floppy_shutdown(unsigned long data)
 {
        unsigned long flags;
 
-       if (!initialising)
+       if (initialized)
                show_floppy();
        cancel_activity();
 
@@ -1915,7 +1884,7 @@ static void floppy_shutdown(unsigned long data)
 
        /* avoid dma going to a random drive after shutdown */
 
-       if (!initialising)
+       if (initialized)
                DPRINT("floppy timeout called\n");
        FDCS->reset = 1;
        if (cont) {
@@ -1925,7 +1894,7 @@ static void floppy_shutdown(unsigned long data)
                pr_info("no cont in shutdown!\n");
                process_fd_request();
        }
-       is_alive("floppy shutdown");
+       is_alive(__func__, "");
 }
 
 /* start motor, check media-changed condition and write protection */
@@ -1968,10 +1937,7 @@ static void floppy_ready(void)
        if (fdc_dtr())
                return;
 
-#ifdef DCL_DEBUG
-       if (DP->flags & FD_DEBUG)
-               DPRINT("calling disk change from floppy_ready\n");
-#endif
+       debug_dcl(DP->flags, "calling disk change from floppy_ready\n");
        if (!(raw_cmd->flags & FD_RAW_NO_MOTOR) &&
            disk_change(current_drive) && !DP->select_delay)
                twaddle();      /* this clears the dcl on certain
@@ -1999,14 +1965,11 @@ static void floppy_ready(void)
 
 static void floppy_start(void)
 {
-       reschedule_timeout(current_reqD, "floppy start", 0);
+       reschedule_timeout(current_reqD, "floppy start");
 
        scandrives();
-#ifdef DCL_DEBUG
-       if (DP->flags & FD_DEBUG)
-               DPRINT("setting NEWCHANGE in floppy_start\n");
-#endif
-       SETF(FD_DISK_NEWCHANGE);
+       debug_dcl(DP->flags, "setting NEWCHANGE in floppy_start\n");
+       set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
        floppy_ready();
 }
 
@@ -2026,7 +1989,7 @@ static void floppy_start(void)
 
 static void do_wakeup(void)
 {
-       reschedule_timeout(MAXTIMEOUT, "do wakeup", 0);
+       reschedule_timeout(MAXTIMEOUT, "do wakeup");
        cont = NULL;
        command_status += 2;
        wake_up(&command_done);
@@ -2046,7 +2009,7 @@ static struct cont_t intr_cont = {
        .done           = (done_f)empty
 };
 
-static int wait_til_done(void (*handler)(void), int interruptible)
+static int wait_til_done(void (*handler)(void), bool interruptible)
 {
        int ret;
 
@@ -2064,7 +2027,7 @@ static int wait_til_done(void (*handler)(void), int interruptible)
                        if (command_status >= 2 || !NO_SIGNAL)
                                break;
 
-                       is_alive("wait_til_done");
+                       is_alive(__func__, "");
                        schedule();
                }
 
@@ -2180,7 +2143,6 @@ static void format_interrupt(void)
        cont->redo();
 }
 
-#define CODE2SIZE (ssize = ((1 << SIZECODE) + 3) >> 2)
 #define FM_MODE(x, y) ((y) & ~(((x)->rate & 0x80) >> 1))
 #define CT(x) ((x) | 0xc0)
 
@@ -2258,7 +2220,7 @@ static void redo_format(void)
        buffer_track = -1;
        setup_format_params(format_req.track << STRETCH(_floppy));
        floppy_start();
-       debugt("queue format request");
+       debugt(__func__, "queue format request");
 }
 
 static struct cont_t format_cont = {
@@ -2272,7 +2234,7 @@ static int do_format(int drive, struct format_descr *tmp_format_req)
 {
        int ret;
 
-       if (lock_fdc(drive, 1))
+       if (lock_fdc(drive, true))
                return -EINTR;
 
        set_floppy(drive);
@@ -2289,7 +2251,9 @@ static int do_format(int drive, struct format_descr *tmp_format_req)
        format_errors = 0;
        cont = &format_cont;
        errors = &format_errors;
-       IWAIT(redo_format);
+       ret = wait_til_done(redo_format, true);
+       if (ret == -EINTR)
+               return -EINTR;
        process_fd_request();
        return ret;
 }
@@ -2323,9 +2287,11 @@ static void request_done(int uptodate)
        struct request *req = current_req;
        unsigned long flags;
        int block;
+       char msg[sizeof("request done ") + sizeof(int) * 3];
 
        probing = 0;
-       reschedule_timeout(MAXTIMEOUT, "request done", uptodate);
+       snprintf(msg, sizeof(msg), "request done %d", uptodate);
+       reschedule_timeout(MAXTIMEOUT, msg);
 
        if (!req) {
                pr_info("floppy.c: no request in request_done\n");
@@ -2380,7 +2346,7 @@ static void rw_interrupt(void)
                DRS->first_read_date = jiffies;
 
        nr_sectors = 0;
-       CODE2SIZE;
+       ssize = DIV_ROUND_UP(1 << SIZECODE, 4);
 
        if (ST1 & ST1_EOC)
                eoc = 1;
@@ -2396,7 +2362,6 @@ static void rw_interrupt(void)
                       R_HEAD - HEAD) * SECT_PER_TRACK +
                      R_SECTOR - SECTOR + eoc) << SIZECODE >> 2;
 
-#ifdef FLOPPY_SANITY_CHECK
        if (nr_sectors / ssize >
            DIV_ROUND_UP(in_sector_offset + current_count_sectors, ssize)) {
                DPRINT("long rw: %x instead of %lx\n",
@@ -2409,7 +2374,6 @@ static void rw_interrupt(void)
                        SECT_PER_TRACK, fsector_t, ssize);
                pr_info("in_sector_offset=%d\n", in_sector_offset);
        }
-#endif
 
        nr_sectors -= in_sector_offset;
        INFBOUND(nr_sectors, 0);
@@ -2514,7 +2478,6 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
                                              blk_rq_sectors(current_req));
 
        remaining = current_count_sectors << 9;
-#ifdef FLOPPY_SANITY_CHECK
        if (remaining > blk_rq_bytes(current_req) && CT(COMMAND) == FD_WRITE) {
                DPRINT("in copy buffer\n");
                pr_info("current_count_sectors=%ld\n", current_count_sectors);
@@ -2526,7 +2489,6 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
                pr_info("max_sector=%d\n", max_sector);
                pr_info("ssize=%d\n", ssize);
        }
-#endif
 
        buffer_max = max(max_sector, buffer_max);
 
@@ -2542,7 +2504,6 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
                SUPBOUND(size, remaining);
 
                buffer = page_address(bv->bv_page) + bv->bv_offset;
-#ifdef FLOPPY_SANITY_CHECK
                if (dma_buffer + size >
                    floppy_track_buffer + (max_buffer_sectors << 10) ||
                    dma_buffer < floppy_track_buffer) {
@@ -2560,7 +2521,7 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
                }
                if (((unsigned long)buffer) % 512)
                        DPRINT("%p buffer not aligned\n", buffer);
-#endif
+
                if (CT(COMMAND) == FD_READ)
                        memcpy(buffer, dma_buffer, size);
                else
@@ -2569,13 +2530,11 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
                remaining -= size;
                dma_buffer += size;
        }
-#ifdef FLOPPY_SANITY_CHECK
        if (remaining) {
                if (remaining > 0)
                        max_sector -= remaining >> 9;
                DPRINT("weirdness: remaining %d\n", remaining >> 9);
        }
-#endif
 }
 
 /* work around a bug in pseudo DMA
@@ -2595,13 +2554,11 @@ static void virtualdmabug_workaround(void)
 
                hard_sectors = raw_cmd->length >> (7 + SIZECODE);
                end_sector = SECTOR + hard_sectors - 1;
-#ifdef FLOPPY_SANITY_CHECK
                if (end_sector > SECT_PER_TRACK) {
                        pr_info("too many sectors %d > %d\n",
                                end_sector, SECT_PER_TRACK);
                        return;
                }
-#endif
                SECT_PER_TRACK = end_sector;
                                        /* make sure SECT_PER_TRACK
                                         * points to end of transfer */
@@ -2644,7 +2601,7 @@ static int make_raw_rw_request(void)
                raw_cmd->flags |= FD_RAW_WRITE;
                COMMAND = FM_MODE(_floppy, FD_WRITE);
        } else {
-               DPRINT("make_raw_rw_request: unknown command\n");
+               DPRINT("%s: unknown command\n", __func__);
                return 0;
        }
 
@@ -2662,7 +2619,8 @@ static int make_raw_rw_request(void)
        HEAD = fsector_t / _floppy->sect;
 
        if (((_floppy->stretch & (FD_SWAPSIDES | FD_SECTBASEMASK)) ||
-            TESTF(FD_NEED_TWADDLE)) && fsector_t < _floppy->sect)
+            test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags)) &&
+           fsector_t < _floppy->sect)
                max_sector = _floppy->sect;
 
        /* 2M disks have phantom sectors on the first track */
@@ -2688,7 +2646,7 @@ static int make_raw_rw_request(void)
        raw_cmd->track = TRACK << STRETCH(_floppy);
        DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, HEAD);
        GAP = _floppy->gap;
-       CODE2SIZE;
+       ssize = DIV_ROUND_UP(1 << SIZECODE, 4);
        SECT_PER_TRACK = _floppy->sect << 2 >> SIZECODE;
        SECTOR = ((fsector_t % _floppy->sect) << 2 >> SIZECODE) +
            FD_SECTBASE(_floppy);
@@ -2784,7 +2742,7 @@ static int make_raw_rw_request(void)
                        raw_cmd->kernel_data = current_req->buffer;
                        raw_cmd->length = current_count_sectors << 9;
                        if (raw_cmd->length == 0) {
-                               DPRINT("zero dma transfer attempted from make_raw_request\n");
+                               DPRINT("%s: zero dma transfer attempted\n", __func__);
                                DPRINT("indirect=%d direct=%d fsector_t=%d\n",
                                       indirect, direct, fsector_t);
                                return 0;
@@ -2819,10 +2777,8 @@ static int make_raw_rw_request(void)
                 * if we get here, we know that the write
                 * is either aligned or the data already in the buffer
                 * (buffer will be overwritten) */
-#ifdef FLOPPY_SANITY_CHECK
                if (in_sector_offset && buffer_track == -1)
                        DPRINT("internal error offset !=0 on write\n");
-#endif
                buffer_track = raw_cmd->track;
                buffer_drive = current_drive;
                copy_buffer(ssize, max_sector,
@@ -2836,7 +2792,6 @@ static int make_raw_rw_request(void)
        raw_cmd->length = in_sector_offset + current_count_sectors;
        raw_cmd->length = ((raw_cmd->length - 1) | (ssize - 1)) + 1;
        raw_cmd->length <<= 9;
-#ifdef FLOPPY_SANITY_CHECK
        if ((raw_cmd->length < current_count_sectors << 9) ||
            (raw_cmd->kernel_data != current_req->buffer &&
             CT(COMMAND) == FD_WRITE &&
@@ -2893,7 +2848,6 @@ static int make_raw_rw_request(void)
                DPRINT("zero dma transfer attempted from make_raw_request\n");
                return 0;
        }
-#endif
 
        virtualdmabug_workaround();
        return 2;
@@ -2901,7 +2855,6 @@ static int make_raw_rw_request(void)
 
 static void redo_fd_request(void)
 {
-#define REPEAT {request_done(0); continue; }
        int drive;
        int tmp;
 
@@ -2909,63 +2862,63 @@ static void redo_fd_request(void)
        if (current_drive < N_DRIVE)
                floppy_off(current_drive);
 
-       for (;;) {
-               if (!current_req) {
-                       struct request *req;
-
-                       spin_lock_irq(floppy_queue->queue_lock);
-                       req = blk_fetch_request(floppy_queue);
-                       spin_unlock_irq(floppy_queue->queue_lock);
-                       if (!req) {
-                               do_floppy = NULL;
-                               unlock_fdc();
-                               return;
-                       }
-                       current_req = req;
-               }
-               drive = (long)current_req->rq_disk->private_data;
-               set_fdc(drive);
-               reschedule_timeout(current_reqD, "redo fd request", 0);
+do_request:
+       if (!current_req) {
+               struct request *req;
 
-               set_floppy(drive);
-               raw_cmd = &default_raw_cmd;
-               raw_cmd->flags = 0;
-               if (start_motor(redo_fd_request))
+               spin_lock_irq(floppy_queue->queue_lock);
+               req = blk_fetch_request(floppy_queue);
+               spin_unlock_irq(floppy_queue->queue_lock);
+               if (!req) {
+                       do_floppy = NULL;
+                       unlock_fdc();
                        return;
-               disk_change(current_drive);
-               if (test_bit(current_drive, &fake_change) ||
-                   TESTF(FD_DISK_CHANGED)) {
-                       DPRINT("disk absent or changed during operation\n");
-                       REPEAT;
-               }
-               if (!_floppy) { /* Autodetection */
-                       if (!probing) {
-                               DRS->probed_format = 0;
-                               if (next_valid_format()) {
-                                       DPRINT("no autodetectable formats\n");
-                                       _floppy = NULL;
-                                       REPEAT;
-                               }
-                       }
-                       probing = 1;
-                       _floppy =
-                           floppy_type + DP->autodetect[DRS->probed_format];
-               } else
-                       probing = 0;
-               errors = &(current_req->errors);
-               tmp = make_raw_rw_request();
-               if (tmp < 2) {
-                       request_done(tmp);
-                       continue;
                }
+               current_req = req;
+       }
+       drive = (long)current_req->rq_disk->private_data;
+       set_fdc(drive);
+       reschedule_timeout(current_reqD, "redo fd request");
 
-               if (TESTF(FD_NEED_TWADDLE))
-                       twaddle();
-               schedule_bh(floppy_start);
-               debugt("queue fd request");
+       set_floppy(drive);
+       raw_cmd = &default_raw_cmd;
+       raw_cmd->flags = 0;
+       if (start_motor(redo_fd_request))
                return;
+
+       disk_change(current_drive);
+       if (test_bit(current_drive, &fake_change) ||
+           test_bit(FD_DISK_CHANGED_BIT, &DRS->flags)) {
+               DPRINT("disk absent or changed during operation\n");
+               request_done(0);
+               goto do_request;
        }
-#undef REPEAT
+       if (!_floppy) { /* Autodetection */
+               if (!probing) {
+                       DRS->probed_format = 0;
+                       if (next_valid_format()) {
+                               DPRINT("no autodetectable formats\n");
+                               _floppy = NULL;
+                               request_done(0);
+                               goto do_request;
+                       }
+               }
+               probing = 1;
+               _floppy = floppy_type + DP->autodetect[DRS->probed_format];
+       } else
+               probing = 0;
+       errors = &(current_req->errors);
+       tmp = make_raw_rw_request();
+       if (tmp < 2) {
+               request_done(tmp);
+               goto do_request;
+       }
+
+       if (test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags))
+               twaddle();
+       schedule_bh(floppy_start);
+       debugt(__func__, "queue fd request");
+       return;
 }
 
 static struct cont_t rw_cont = {
@@ -2984,7 +2937,7 @@ static void process_fd_request(void)
 static void do_fd_request(struct request_queue *q)
 {
        if (max_buffer_sectors == 0) {
-               pr_info("VFS: do_fd_request called on non-open device\n");
+               pr_info("VFS: %s called on non-open device\n", __func__);
                return;
        }
 
@@ -2999,12 +2952,12 @@ static void do_fd_request(struct request_queue *q)
        if (test_bit(0, &fdc_busy)) {
                /* fdc busy, this new request will be treated when the
                   current one is done */
-               is_alive("do fd request, old request running");
+               is_alive(__func__, "old request running");
                return;
        }
-       lock_fdc(MAXTIMEOUT, 0);
+       lock_fdc(MAXTIMEOUT, false);
        process_fd_request();
-       is_alive("do fd request");
+       is_alive(__func__, "");
 }
 
 static struct cont_t poll_cont = {
@@ -3014,23 +2967,18 @@ static struct cont_t poll_cont = {
        .done           = generic_done
 };
 
-static int poll_drive(int interruptible, int flag)
+static int poll_drive(bool interruptible, int flag)
 {
-       int ret;
-
        /* no auto-sense, just clear dcl */
        raw_cmd = &default_raw_cmd;
        raw_cmd->flags = flag;
        raw_cmd->track = 0;
        raw_cmd->cmd_count = 0;
        cont = &poll_cont;
-#ifdef DCL_DEBUG
-       if (DP->flags & FD_DEBUG)
-               DPRINT("setting NEWCHANGE in poll_drive\n");
-#endif
-       SETF(FD_DISK_NEWCHANGE);
-       WAIT(floppy_ready);
-       return ret;
+       debug_dcl(DP->flags, "setting NEWCHANGE in poll_drive\n");
+       set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
+
+       return wait_til_done(floppy_ready, interruptible);
 }
 
 /*
@@ -3050,7 +2998,7 @@ static struct cont_t reset_cont = {
        .done           = generic_done
 };
 
-static int user_reset_fdc(int drive, int arg, int interruptible)
+static int user_reset_fdc(int drive, int arg, bool interruptible)
 {
        int ret;
 
@@ -3061,7 +3009,9 @@ static int user_reset_fdc(int drive, int arg, int interruptible)
                FDCS->reset = 1;
        if (FDCS->reset) {
                cont = &reset_cont;
-               WAIT(reset_fdc);
+               ret = wait_til_done(reset_fdc, interruptible);
+               if (ret == -EINTR)
+                       return -EINTR;
        }
        process_fd_request();
        return 0;
@@ -3083,14 +3033,6 @@ static inline int fd_copyin(void __user *param, void *address,
        return copy_from_user(address, param, size) ? -EFAULT : 0;
 }
 
-#define _COPYOUT(x)    (copy_to_user((void __user *)param, &(x), sizeof(x)) \
-                        ? -EFAULT : 0)
-#define _COPYIN(x)     (copy_from_user(&(x), (void __user *)param, sizeof(x)) \
-                        ? -EFAULT : 0)
-
-#define COPYOUT(x)     ECALL(_COPYOUT(x))
-#define COPYIN(x)      ECALL(_COPYIN(x))
-
 static inline const char *drive_name(int type, int drive)
 {
        struct floppy_struct *floppy;
@@ -3161,24 +3103,29 @@ static struct cont_t raw_cmd_cont = {
        .done           = raw_cmd_done
 };
 
-static inline int raw_cmd_copyout(int cmd, char __user *param,
+static inline int raw_cmd_copyout(int cmd, void __user *param,
                                  struct floppy_raw_cmd *ptr)
 {
        int ret;
 
        while (ptr) {
-               COPYOUT(*ptr);
+               ret = copy_to_user(param, ptr, sizeof(*ptr));
+               if (ret)
+                       return -EFAULT;
                param += sizeof(struct floppy_raw_cmd);
                if ((ptr->flags & FD_RAW_READ) && ptr->buffer_length) {
                        if (ptr->length >= 0 &&
                            ptr->length <= ptr->buffer_length) {
                                long length = ptr->buffer_length - ptr->length;
-                               ECALL(fd_copyout(ptr->data, ptr->kernel_data,
-                                                length));
+                               ret = fd_copyout(ptr->data, ptr->kernel_data,
+                                                length);
+                               if (ret)
+                                       return ret;
                        }
                }
                ptr = ptr->next;
        }
+
        return 0;
 }
 
@@ -3201,7 +3148,7 @@ static void raw_cmd_free(struct floppy_raw_cmd **ptr)
        }
 }
 
-static inline int raw_cmd_copyin(int cmd, char __user *param,
+static inline int raw_cmd_copyin(int cmd, void __user *param,
                                 struct floppy_raw_cmd **rcmd)
 {
        struct floppy_raw_cmd *ptr;
@@ -3209,17 +3156,19 @@ static inline int raw_cmd_copyin(int cmd, char __user *param,
        int i;
 
        *rcmd = NULL;
-       while (1) {
-               ptr = (struct floppy_raw_cmd *)
-                   kmalloc(sizeof(struct floppy_raw_cmd), GFP_USER);
-               if (!ptr)
-                       return -ENOMEM;
-               *rcmd = ptr;
-               COPYIN(*ptr);
-               ptr->next = NULL;
-               ptr->buffer_length = 0;
-               param += sizeof(struct floppy_raw_cmd);
-               if (ptr->cmd_count > 33)
+
+loop:
+       ptr = kmalloc(sizeof(struct floppy_raw_cmd), GFP_USER);
+       if (!ptr)
+               return -ENOMEM;
+       *rcmd = ptr;
+       ret = copy_from_user(ptr, param, sizeof(*ptr));
+       if (ret)
+               return -EFAULT;
+       ptr->next = NULL;
+       ptr->buffer_length = 0;
+       param += sizeof(struct floppy_raw_cmd);
+       if (ptr->cmd_count > 33)
                        /* the command may now also take up the space
                         * initially intended for the reply & the
                         * reply count. Needed for long 82078 commands
@@ -3228,31 +3177,35 @@ static inline int raw_cmd_copyin(int cmd, char __user *param,
                         * 16 bytes for a structure, you'll one day
                         * discover that you really need 17...
                         */
+               return -EINVAL;
+
+       for (i = 0; i < 16; i++)
+               ptr->reply[i] = 0;
+       ptr->resultcode = 0;
+       ptr->kernel_data = NULL;
+
+       if (ptr->flags & (FD_RAW_READ | FD_RAW_WRITE)) {
+               if (ptr->length <= 0)
                        return -EINVAL;
+               ptr->kernel_data = (char *)fd_dma_mem_alloc(ptr->length);
+               fallback_on_nodma_alloc(&ptr->kernel_data, ptr->length);
+               if (!ptr->kernel_data)
+                       return -ENOMEM;
+               ptr->buffer_length = ptr->length;
+       }
+       if (ptr->flags & FD_RAW_WRITE) {
+               ret = fd_copyin(ptr->data, ptr->kernel_data, ptr->length);
+               if (ret)
+                       return ret;
+       }
 
-               for (i = 0; i < 16; i++)
-                       ptr->reply[i] = 0;
-               ptr->resultcode = 0;
-               ptr->kernel_data = NULL;
-
-               if (ptr->flags & (FD_RAW_READ | FD_RAW_WRITE)) {
-                       if (ptr->length <= 0)
-                               return -EINVAL;
-                       ptr->kernel_data =
-                           (char *)fd_dma_mem_alloc(ptr->length);
-                       fallback_on_nodma_alloc(&ptr->kernel_data, ptr->length);
-                       if (!ptr->kernel_data)
-                               return -ENOMEM;
-                       ptr->buffer_length = ptr->length;
-               }
-               if (ptr->flags & FD_RAW_WRITE)
-                       ECALL(fd_copyin(ptr->data, ptr->kernel_data,
-                                       ptr->length));
+       if (ptr->flags & FD_RAW_MORE) {
                rcmd = &(ptr->next);
-               if (!(ptr->flags & FD_RAW_MORE))
-                       return 0;
                ptr->rate &= 0x43;
+               goto loop;
        }
+
+       return 0;
 }
 
 static int raw_cmd_ioctl(int cmd, void __user *param)
@@ -3289,11 +3242,8 @@ static int raw_cmd_ioctl(int cmd, void __user *param)
 
        raw_cmd = my_raw_cmd;
        cont = &raw_cmd_cont;
-       ret = wait_til_done(floppy_start, 1);
-#ifdef DCL_DEBUG
-       if (DP->flags & FD_DEBUG)
-               DPRINT("calling disk change from raw_cmd ioctl\n");
-#endif
+       ret = wait_til_done(floppy_start, true);
+       debug_dcl(DP->flags, "calling disk change from raw_cmd ioctl\n");
 
        if (ret != -EINTR && FDCS->reset)
                ret = -EIO;
@@ -3332,7 +3282,7 @@ static inline int set_geometry(unsigned int cmd, struct floppy_struct *g,
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
                mutex_lock(&open_lock);
-               if (lock_fdc(drive, 1)) {
+               if (lock_fdc(drive, true)) {
                        mutex_unlock(&open_lock);
                        return -EINTR;
                }
@@ -3352,12 +3302,14 @@ static inline int set_geometry(unsigned int cmd, struct floppy_struct *g,
        } else {
                int oldStretch;
 
-               if (lock_fdc(drive, 1))
+               if (lock_fdc(drive, true))
                        return -EINTR;
-               if (cmd != FDDEFPRM)
+               if (cmd != FDDEFPRM) {
                        /* notice a disk change immediately, else
                         * we lose our settings immediately*/
-                       CALL(poll_drive(1, FD_RAW_NEED_DISK));
+                       if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
+                               return -EINTR;
+               }
                oldStretch = g->stretch;
                user_params[drive] = *g;
                if (buffer_drive == drive)
@@ -3436,9 +3388,10 @@ static int get_floppy_geometry(int drive, int type, struct floppy_struct **g)
        if (type)
                *g = &floppy_type[type];
        else {
-               if (lock_fdc(drive, 0))
+               if (lock_fdc(drive, false))
+                       return -EINTR;
+               if (poll_drive(false, 0) == -EINTR)
                        return -EINTR;
-               CALL(poll_drive(0, 0));
                process_fd_request();
                *g = current_type[drive];
        }
@@ -3467,8 +3420,6 @@ static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
 static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
                    unsigned long param)
 {
-#define FD_IOCTL_ALLOWED (mode & (FMODE_WRITE|FMODE_WRITE_IOCTL))
-
        int drive = (long)bdev->bd_disk->private_data;
        int type = ITYPE(UDRS->fd_device);
        int i;
@@ -3480,7 +3431,7 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
                struct floppy_max_errors max_errors;
                struct floppy_drive_params dp;
        } inparam;              /* parameters coming from user space */
-       const char *outparam;   /* parameters passed back to user space */
+       const void *outparam;   /* parameters passed back to user space */
 
        /* convert compatibility eject ioctls into floppy eject ioctl.
         * We do this in order to provide a means to eject floppy disks before
@@ -3496,10 +3447,12 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
                return -EINVAL;
 
        /* convert the old style command into a new style command */
-       ECALL(normalize_ioctl(&cmd, &size));
+       ret = normalize_ioctl(&cmd, &size);
+       if (ret)
+               return ret;
 
        /* permission checks */
-       if (((cmd & 0x40) && !FD_IOCTL_ALLOWED) ||
+       if (((cmd & 0x40) && !(mode & (FMODE_WRITE | FMODE_WRITE_IOCTL))) ||
            ((cmd & 0x80) && !capable(CAP_SYS_ADMIN)))
                return -EPERM;
 
@@ -3508,27 +3461,30 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
 
        /* copyin */
        memset(&inparam, 0, sizeof(inparam));
-       if (_IOC_DIR(cmd) & _IOC_WRITE)
-               ECALL(fd_copyin((void __user *)param, &inparam, size));
+       if (_IOC_DIR(cmd) & _IOC_WRITE) {
+               ret = fd_copyin((void __user *)param, &inparam, size);
+               if (ret)
+                       return ret;
+       }
 
        switch (cmd) {
        case FDEJECT:
                if (UDRS->fd_ref != 1)
                        /* somebody else has this drive open */
                        return -EBUSY;
-               if (lock_fdc(drive, 1))
+               if (lock_fdc(drive, true))
                        return -EINTR;
 
                /* do the actual eject. Fails on
                 * non-Sparc architectures */
                ret = fd_eject(UNIT(drive));
 
-               USETF(FD_DISK_CHANGED);
-               USETF(FD_VERIFY);
+               set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
+               set_bit(FD_VERIFY_BIT, &UDRS->flags);
                process_fd_request();
                return ret;
        case FDCLRPRM:
-               if (lock_fdc(drive, 1))
+               if (lock_fdc(drive, true))
                        return -EINTR;
                current_type[drive] = NULL;
                floppy_sizes[drive] = MAX_DISK_SIZE << 1;
@@ -3538,9 +3494,10 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
        case FDDEFPRM:
                return set_geometry(cmd, &inparam.g, drive, type, bdev);
        case FDGETPRM:
-               ECALL(get_floppy_geometry(drive, type,
-                                         (struct floppy_struct **)
-                                         &outparam));
+               ret = get_floppy_geometry(drive, type,
+                                         (struct floppy_struct **)&outparam);
+               if (ret)
+                       return ret;
                break;
        case FDMSGON:
                UDP->flags |= FTD_MSG;
@@ -3549,9 +3506,10 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
                UDP->flags &= ~FTD_MSG;
                return 0;
        case FDFMTBEG:
-               if (lock_fdc(drive, 1))
+               if (lock_fdc(drive, true))
+                       return -EINTR;
+               if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
                        return -EINTR;
-               CALL(poll_drive(1, FD_RAW_NEED_DISK));
                ret = UDRS->flags;
                process_fd_request();
                if (ret & FD_VERIFY)
@@ -3565,59 +3523,62 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
                return do_format(drive, &inparam.f);
        case FDFMTEND:
        case FDFLUSH:
-               if (lock_fdc(drive, 1))
+               if (lock_fdc(drive, true))
                        return -EINTR;
                return invalidate_drive(bdev);
        case FDSETEMSGTRESH:
                UDP->max_errors.reporting = (unsigned short)(param & 0x0f);
                return 0;
        case FDGETMAXERRS:
-               outparam = (const char *)&UDP->max_errors;
+               outparam = &UDP->max_errors;
                break;
        case FDSETMAXERRS:
                UDP->max_errors = inparam.max_errors;
                break;
        case FDGETDRVTYP:
                outparam = drive_name(type, drive);
-               SUPBOUND(size, strlen(outparam) + 1);
+               SUPBOUND(size, strlen((const char *)outparam) + 1);
                break;
        case FDSETDRVPRM:
                *UDP = inparam.dp;
                break;
        case FDGETDRVPRM:
-               outparam = (const char *)UDP;
+               outparam = UDP;
                break;
        case FDPOLLDRVSTAT:
-               if (lock_fdc(drive, 1))
+               if (lock_fdc(drive, true))
+                       return -EINTR;
+               if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
                        return -EINTR;
-               CALL(poll_drive(1, FD_RAW_NEED_DISK));
                process_fd_request();
                /* fall through */
        case FDGETDRVSTAT:
-               outparam = (const char *)UDRS;
+               outparam = UDRS;
                break;
        case FDRESET:
-               return user_reset_fdc(drive, (int)param, 1);
+               return user_reset_fdc(drive, (int)param, true);
        case FDGETFDCSTAT:
-               outparam = (const char *)UFDCS;
+               outparam = UFDCS;
                break;
        case FDWERRORCLR:
                memset(UDRWE, 0, sizeof(*UDRWE));
                return 0;
        case FDWERRORGET:
-               outparam = (const char *)UDRWE;
+               outparam = UDRWE;
                break;
        case FDRAWCMD:
                if (type)
                        return -EINVAL;
-               if (lock_fdc(drive, 1))
+               if (lock_fdc(drive, true))
                        return -EINTR;
                set_floppy(drive);
-               CALL(i = raw_cmd_ioctl(cmd, (void __user *)param));
+               i = raw_cmd_ioctl(cmd, (void __user *)param);
+               if (i == -EINTR)
+                       return -EINTR;
                process_fd_request();
                return i;
        case FDTWADDLE:
-               if (lock_fdc(drive, 1))
+               if (lock_fdc(drive, true))
                        return -EINTR;
                twaddle();
                process_fd_request();
@@ -3721,8 +3682,8 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
                goto out2;
 
        if (!UDRS->fd_ref && (UDP->flags & FD_BROKEN_DCL)) {
-               USETF(FD_DISK_CHANGED);
-               USETF(FD_VERIFY);
+               set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
+               set_bit(FD_VERIFY_BIT, &UDRS->flags);
        }
 
        if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (mode & FMODE_EXCL)))
@@ -3782,11 +3743,12 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
                if (mode & (FMODE_READ|FMODE_WRITE)) {
                        UDRS->last_checked = 0;
                        check_disk_change(bdev);
-                       if (UTESTF(FD_DISK_CHANGED))
+                       if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags))
                                goto out;
                }
                res = -EROFS;
-               if ((mode & FMODE_WRITE) && !(UTESTF(FD_DISK_WRITABLE)))
+               if ((mode & FMODE_WRITE) &&
+                   !test_bit(FD_DISK_WRITABLE_BIT, &UDRS->flags))
                        goto out;
        }
        mutex_unlock(&open_lock);
@@ -3810,17 +3772,18 @@ static int check_floppy_change(struct gendisk *disk)
 {
        int drive = (long)disk->private_data;
 
-       if (UTESTF(FD_DISK_CHANGED) || UTESTF(FD_VERIFY))
+       if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
+           test_bit(FD_VERIFY_BIT, &UDRS->flags))
                return 1;
 
        if (time_after(jiffies, UDRS->last_checked + UDP->checkfreq)) {
-               lock_fdc(drive, 0);
-               poll_drive(0, 0);
+               lock_fdc(drive, false);
+               poll_drive(false, 0);
                process_fd_request();
        }
 
-       if (UTESTF(FD_DISK_CHANGED) ||
-           UTESTF(FD_VERIFY) ||
+       if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
+           test_bit(FD_VERIFY_BIT, &UDRS->flags) ||
            test_bit(drive, &fake_change) ||
            (!ITYPE(UDRS->fd_device) && !current_type[drive]))
                return 1;
@@ -3891,14 +3854,16 @@ static int floppy_revalidate(struct gendisk *disk)
        int cf;
        int res = 0;
 
-       if (UTESTF(FD_DISK_CHANGED) ||
-           UTESTF(FD_VERIFY) || test_bit(drive, &fake_change) || NO_GEOM) {
+       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) {
                        pr_info("VFS: revalidate called on non-open device.\n");
                        return -EFAULT;
                }
-               lock_fdc(drive, 0);
-               cf = UTESTF(FD_DISK_CHANGED) || UTESTF(FD_VERIFY);
+               lock_fdc(drive, false);
+               cf = (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
+                     test_bit(FD_VERIFY_BIT, &UDRS->flags));
                if (!(cf || test_bit(drive, &fake_change) || NO_GEOM)) {
                        process_fd_request();   /*already done by another thread */
                        return 0;
@@ -3908,7 +3873,7 @@ static int floppy_revalidate(struct gendisk *disk)
                if (buffer_drive == drive)
                        buffer_track = -1;
                clear_bit(drive, &fake_change);
-               UCLEARF(FD_DISK_CHANGED);
+               clear_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
                if (cf)
                        UDRS->generation++;
                if (NO_GEOM) {
@@ -3916,7 +3881,7 @@ static int floppy_revalidate(struct gendisk *disk)
                        res = __floppy_read_block_0(opened_bdev[drive]);
                } else {
                        if (cf)
-                               poll_drive(0, FD_RAW_NEED_DISK);
+                               poll_drive(false, FD_RAW_NEED_DISK);
                        process_fd_request();
                }
        }
@@ -4173,7 +4138,7 @@ static int floppy_resume(struct device *dev)
 
        for (fdc = 0; fdc < N_FDC; fdc++)
                if (FDCS->address != -1)
-                       user_reset_fdc(-1, FD_RESET_ALWAYS, 0);
+                       user_reset_fdc(-1, FD_RESET_ALWAYS, false);
 
        return 0;
 }
@@ -4258,7 +4223,7 @@ static int __init floppy_init(void)
                else
                        floppy_sizes[i] = MAX_DISK_SIZE << 1;
 
-       reschedule_timeout(MAXTIMEOUT, "floppy init", MAXTIMEOUT);
+       reschedule_timeout(MAXTIMEOUT, "floppy init");
        config_types();
 
        for (i = 0; i < N_FDC; i++) {
@@ -4298,9 +4263,9 @@ static int __init floppy_init(void)
        for (drive = 0; drive < N_DRIVE; drive++) {
                memset(UDRS, 0, sizeof(*UDRS));
                memset(UDRWE, 0, sizeof(*UDRWE));
-               USETF(FD_DISK_NEWCHANGE);
-               USETF(FD_DISK_CHANGED);
-               USETF(FD_VERIFY);
+               set_bit(FD_DISK_NEWCHANGE_BIT, &UDRS->flags);
+               set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
+               set_bit(FD_VERIFY_BIT, &UDRS->flags);
                UDRS->fd_device = -1;
                floppy_track_buffer = NULL;
                max_buffer_sectors = 0;
@@ -4320,7 +4285,7 @@ static int __init floppy_init(void)
                if (FDCS->address == -1)
                        continue;
                FDCS->rawcmd = 2;
-               if (user_reset_fdc(-1, FD_RESET_ALWAYS, 0)) {
+               if (user_reset_fdc(-1, FD_RESET_ALWAYS, false)) {
                        /* free ioports reserved by floppy_grab_irq_and_dma() */
                        floppy_release_regions(fdc);
                        FDCS->address = -1;
@@ -4343,12 +4308,12 @@ static int __init floppy_init(void)
                 * properly, so force a reset for the standard FDC clones,
                 * to avoid interrupt garbage.
                 */
-               user_reset_fdc(-1, FD_RESET_ALWAYS, 0);
+               user_reset_fdc(-1, FD_RESET_ALWAYS, false);
        }
        fdc = 0;
        del_timer(&fd_timeout);
        current_drive = 0;
-       initialising = 0;
+       initialized = true;
        if (have_no_fdc) {
                DPRINT("no floppy controllers found\n");
                err = have_no_fdc;
@@ -4528,11 +4493,9 @@ cleanup:
 static void floppy_release_irq_and_dma(void)
 {
        int old_fdc;
-#ifdef FLOPPY_SANITY_CHECK
 #ifndef __sparc__
        int drive;
 #endif
-#endif
        long tmpsize;
        unsigned long tmpaddr;
        unsigned long flags;
@@ -4563,7 +4526,6 @@ static void floppy_release_irq_and_dma(void)
                buffer_min = buffer_max = -1;
                fd_dma_mem_free(tmpaddr, tmpsize);
        }
-#ifdef FLOPPY_SANITY_CHECK
 #ifndef __sparc__
        for (drive = 0; drive < N_FDC * 4; drive++)
                if (timer_pending(motor_off_timer + drive))
@@ -4576,7 +4538,6 @@ static void floppy_release_irq_and_dma(void)
                pr_info("auxiliary floppy timer still active\n");
        if (work_pending(&floppy_work))
                pr_info("work still pending\n");
-#endif
        old_fdc = fdc;
        for (fdc = 0; fdc < N_FDC; fdc++)
                if (FDCS->address != -1)