Might as well make it cleaner...
Joe Perches (13):
drivers/block/floppy.c: Remove macro LOCK_FDC
drivers/block/floppy.c: Add debug_dcl(...) macro
drivers/block/floppy.c: Remove [U]CLEARF, [U]SETF, and [U]TESTF macros
drivers/block/floppy.c: Remove most uses of CALL and ECALL macros
drivers/block/floppy.c: remove [_]COPYIN [_]COPYOUT and ECALL macros
drivers/block/floppy.c: remove macros CALL, WAIT and IWAIT
drivers/block/floppy.c: convert int 1/0 to bool true/false
drivers/block/floppy.c: Move leading && and || to preceding line
drivers/block/floppy.c: remove #define DEVICE_NAME "floppy"
drivers/block/floppy.c: Convert int initialising to bool initialized
drivers/block/floppy.c: Add function is_ready_state
drivers/block/floppy.c: Readd SunOS eject cmd comment
drivers/block/floppy.c: Remove unnecessary return and braces
drivers/block/floppy.c | 410 ++++++++++++++++++++++++------------------------
1 files changed, 208 insertions(+), 202 deletions(-)
Macros with hidden returns aren't nice.
Signed-off-by: Joe Perches <[email protected]>
---
drivers/block/floppy.c | 43 ++++++++++++++++++++++++++-----------------
1 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 4521582..3e3e5fe 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1434,10 +1434,6 @@ static int _lock_fdc(int drive, int interruptible, int line)
#define lock_fdc(drive, interruptible) \
_lock_fdc(drive, interruptible, __LINE__)
-#define LOCK_FDC(drive, interruptible) \
- if (lock_fdc(drive, interruptible)) \
- return -EINTR;
-
/* unlocks the driver */
static inline void unlock_fdc(void)
{
@@ -2804,7 +2800,9 @@ static int do_format(int drive, struct format_descr *tmp_format_req)
{
int ret;
- LOCK_FDC(drive, 1);
+ if (lock_fdc(drive, 1))
+ return -EINTR;
+
set_floppy(drive);
if (!_floppy ||
_floppy->track > DP->tracks ||
@@ -3584,8 +3582,9 @@ static int user_reset_fdc(int drive, int arg, int interruptible)
{
int ret;
- ret = 0;
- LOCK_FDC(drive, interruptible);
+ if (lock_fdc(drive, interruptible))
+ return -EINTR;
+
if (arg == FD_RESET_ALWAYS)
FDCS->reset = 1;
if (FDCS->reset) {
@@ -3593,7 +3592,7 @@ static int user_reset_fdc(int drive, int arg, int interruptible)
WAIT(reset_fdc);
}
process_fd_request();
- return ret;
+ return 0;
}
/*
@@ -3879,7 +3878,9 @@ static inline int set_geometry(unsigned int cmd, struct floppy_struct *g,
mutex_unlock(&open_lock);
} else {
int oldStretch;
- LOCK_FDC(drive, 1);
+
+ if (lock_fdc(drive, 1))
+ return -EINTR;
if (cmd != FDDEFPRM)
/* notice a disk change immediately, else
* we lose our settings immediately*/
@@ -3962,7 +3963,8 @@ static int get_floppy_geometry(int drive, int type, struct floppy_struct **g)
if (type)
*g = &floppy_type[type];
else {
- LOCK_FDC(drive, 0);
+ if (lock_fdc(drive, 0))
+ return -EINTR;
CALL(poll_drive(0, 0));
process_fd_request();
*g = current_type[drive];
@@ -4037,7 +4039,8 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
if (UDRS->fd_ref != 1)
/* somebody else has this drive open */
return -EBUSY;
- LOCK_FDC(drive, 1);
+ if (lock_fdc(drive, 1))
+ return -EINTR;
/* do the actual eject. Fails on
* non-Sparc architectures */
@@ -4049,7 +4052,8 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
return ret;
case FDCLRPRM:
- LOCK_FDC(drive, 1);
+ if (lock_fdc(drive, 1))
+ return -EINTR;
current_type[drive] = NULL;
floppy_sizes[drive] = MAX_DISK_SIZE << 1;
UDRS->keep_data = 0;
@@ -4074,7 +4078,8 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
return 0;
case FDFMTBEG:
- LOCK_FDC(drive, 1);
+ if (lock_fdc(drive, 1))
+ return -EINTR;
CALL(poll_drive(1, FD_RAW_NEED_DISK));
ret = UDRS->flags;
process_fd_request();
@@ -4091,7 +4096,8 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
case FDFMTEND:
case FDFLUSH:
- LOCK_FDC(drive, 1);
+ if (lock_fdc(drive, 1))
+ return -EINTR;
return invalidate_drive(bdev);
case FDSETEMSGTRESH:
@@ -4120,7 +4126,8 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
break;
case FDPOLLDRVSTAT:
- LOCK_FDC(drive, 1);
+ if (lock_fdc(drive, 1))
+ return -EINTR;
CALL(poll_drive(1, FD_RAW_NEED_DISK));
process_fd_request();
/* fall through */
@@ -4147,14 +4154,16 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
case FDRAWCMD:
if (type)
return -EINVAL;
- LOCK_FDC(drive, 1);
+ if (lock_fdc(drive, 1))
+ return -EINTR;
set_floppy(drive);
CALL(i = raw_cmd_ioctl(cmd, (void __user *)param));
process_fd_request();
return i;
case FDTWADDLE:
- LOCK_FDC(drive, 1);
+ if (lock_fdc(drive, 1))
+ return -EINTR;
twaddle();
process_fd_request();
return 0;
--
1.6.6.rc0.57.gad7a
Converted #ifdef DCL_DEBUG if (test) DPRINTK(...); #endif
to debug_dcl(test, ...);
Signed-off-by: Joe Perches <[email protected]>
---
drivers/block/floppy.c | 83 ++++++++++++++++++------------------------------
1 files changed, 31 insertions(+), 52 deletions(-)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 3e3e5fe..cacb0dd 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -152,6 +152,15 @@
#define DEBUGT 2
#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;
#include <linux/module.h>
@@ -1274,14 +1283,12 @@ static int disk_change(int drive)
}
#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);
if ((fd_inb(FD_DIR) ^ UDP->flags) & 0x80) {
@@ -1330,10 +1337,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;
@@ -1546,10 +1551,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");
@@ -2110,12 +2112,9 @@ 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
+ debug_dcl(DP->flags,
+ "clearing NEWCHANGE flag because of effective seek\n");
+ debug_dcl(DP->flags, "jiffies=%lu\n", jiffies);
CLEARF(FD_DISK_NEWCHANGE); /* effective seek */
DRS->select_date = jiffies;
}
@@ -2135,12 +2134,9 @@ static void check_wp(void)
}
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
+ 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);
else
@@ -2154,10 +2150,7 @@ 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 seek\n");
if (!TESTF(FD_DISK_NEWCHANGE) &&
disk_change(current_drive) && (raw_cmd->flags & FD_RAW_NEED_DISK)) {
@@ -2233,10 +2226,8 @@ static void recal_interrupt(void)
* 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);
DRS->select_date = jiffies;
@@ -2496,10 +2487,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
@@ -2530,10 +2518,7 @@ static void floppy_start(void)
reschedule_timeout(current_reqD, "floppy start", 0);
scandrives();
-#ifdef DCL_DEBUG
- if (DP->flags & FD_DEBUG)
- DPRINT("setting NEWCHANGE in floppy_start\n");
-#endif
+ debug_dcl(DP->flags, "setting NEWCHANGE in floppy_start\n");
SETF(FD_DISK_NEWCHANGE);
floppy_ready();
}
@@ -3552,10 +3537,7 @@ static int poll_drive(int interruptible, int 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
+ debug_dcl(DP->flags, "setting NEWCHANGE in poll_drive\n");
SETF(FD_DISK_NEWCHANGE);
WAIT(floppy_ready);
return ret;
@@ -3817,10 +3799,7 @@ 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
+ debug_dcl(DP->flags, "calling disk change from raw_cmd ioctl\n");
if (ret != -EINTR && FDCS->reset)
ret = -EIO;
--
1.6.6.rc0.57.gad7a
Use clear_bit, set_bit, and test_bit functions directly
Signed-off-by: Joe Perches <[email protected]>
---
drivers/block/floppy.c | 94 ++++++++++++++++++++++++------------------------
1 files changed, 47 insertions(+), 47 deletions(-)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index cacb0dd..afbbd7d 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -305,17 +305,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)
@@ -1290,13 +1284,13 @@ static int disk_change(int drive)
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) {
@@ -1311,7 +1305,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;
}
@@ -2005,11 +1999,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");
@@ -2115,7 +2109,8 @@ static void seek_interrupt(void)
debug_dcl(DP->flags,
"clearing NEWCHANGE flag because of effective seek\n");
debug_dcl(DP->flags, "jiffies=%lu\n", jiffies);
- CLEARF(FD_DISK_NEWCHANGE); /* effective seek */
+ clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
+ /* effective seek */
DRS->select_date = jiffies;
}
DRS->track = ST1;
@@ -2124,23 +2119,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);
+ 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);
}
}
@@ -2152,13 +2147,13 @@ static void seek_floppy(void)
debug_dcl(DP->flags, "calling disk change from seek\n");
- 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;
@@ -2166,7 +2161,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
@@ -2229,7 +2224,7 @@ static void recal_interrupt(void)
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:
@@ -2519,7 +2514,7 @@ static void floppy_start(void)
scandrives();
debug_dcl(DP->flags, "setting NEWCHANGE in floppy_start\n");
- SETF(FD_DISK_NEWCHANGE);
+ set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
floppy_ready();
}
@@ -3175,7 +3170,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 */
@@ -3447,7 +3443,7 @@ static void redo_fd_request(void)
return;
disk_change(current_drive);
if (test_bit(current_drive, &fake_change) ||
- TESTF(FD_DISK_CHANGED)) {
+ test_bit(FD_DISK_CHANGED_BIT, &DRS->flags)) {
DPRINT("disk absent or changed during operation\n");
REPEAT;
}
@@ -3472,7 +3468,7 @@ static void redo_fd_request(void)
continue;
}
- if (TESTF(FD_NEED_TWADDLE))
+ if (test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags))
twaddle();
schedule_bh(floppy_start);
debugt("queue fd request");
@@ -3538,7 +3534,7 @@ static int poll_drive(int interruptible, int flag)
raw_cmd->cmd_count = 0;
cont = &poll_cont;
debug_dcl(DP->flags, "setting NEWCHANGE in poll_drive\n");
- SETF(FD_DISK_NEWCHANGE);
+ set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
WAIT(floppy_ready);
return ret;
}
@@ -4025,8 +4021,8 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
* 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;
@@ -4242,8 +4238,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)))
@@ -4303,11 +4299,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);
@@ -4331,7 +4328,8 @@ 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)) {
@@ -4340,8 +4338,8 @@ static int check_floppy_change(struct gendisk *disk)
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;
@@ -4412,14 +4410,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);
+ 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 */
@@ -4430,7 +4430,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) {
@@ -4965,9 +4965,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;
--
1.6.6.rc0.57.gad7a
Signed-off-by: Joe Perches <[email protected]>
---
drivers/block/floppy.c | 51 ++++++++++++++++++++++++++++++++---------------
1 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index afbbd7d..4a17eae 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -3679,8 +3679,10 @@ static inline int raw_cmd_copyout(int cmd, char __user *param,
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;
@@ -3750,9 +3752,12 @@ static inline int raw_cmd_copyin(int cmd, char __user *param,
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_WRITE) {
+ ret = fd_copyin(ptr->data, ptr->kernel_data,
+ ptr->length);
+ if (ret)
+ return ret;
+ }
rcmd = &(ptr->next);
if (!(ptr->flags & FD_RAW_MORE))
return 0;
@@ -3856,10 +3861,12 @@ static inline int set_geometry(unsigned int cmd, struct floppy_struct *g,
if (lock_fdc(drive, 1))
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(1, FD_RAW_NEED_DISK) == -EINTR)
+ return -EINTR;
+ }
oldStretch = g->stretch;
user_params[drive] = *g;
if (buffer_drive == drive)
@@ -3940,7 +3947,8 @@ static int get_floppy_geometry(int drive, int type, struct floppy_struct **g)
else {
if (lock_fdc(drive, 0))
return -EINTR;
- CALL(poll_drive(0, 0));
+ if (poll_drive(0, 0) == -EINTR)
+ return -EINTR;
process_fd_request();
*g = current_type[drive];
}
@@ -3997,7 +4005,9 @@ 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) ||
@@ -4006,8 +4016,11 @@ 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:
@@ -4039,9 +4052,11 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
return set_geometry(cmd, &inparam.g, drive, type, bdev);
case FDGETPRM:
- ECALL(get_floppy_geometry(drive, type,
+ ret = get_floppy_geometry(drive, type,
(struct floppy_struct **)
- &outparam));
+ &outparam);
+ if (ret)
+ return ret;
break;
case FDMSGON:
@@ -4055,7 +4070,8 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
case FDFMTBEG:
if (lock_fdc(drive, 1))
return -EINTR;
- CALL(poll_drive(1, FD_RAW_NEED_DISK));
+ if (poll_drive(1, FD_RAW_NEED_DISK) == -EINTR)
+ return -EINTR;
ret = UDRS->flags;
process_fd_request();
if (ret & FD_VERIFY)
@@ -4103,7 +4119,8 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
case FDPOLLDRVSTAT:
if (lock_fdc(drive, 1))
return -EINTR;
- CALL(poll_drive(1, FD_RAW_NEED_DISK));
+ if (poll_drive(1, FD_RAW_NEED_DISK) == -EINTR)
+ return -EINTR;
process_fd_request();
/* fall through */
@@ -4132,7 +4149,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
if (lock_fdc(drive, 1))
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;
--
1.6.6.rc0.57.gad7a
Remove these obfuscating macros with hidden returns
Signed-off-by: Joe Perches <[email protected]>
---
drivers/block/floppy.c | 17 ++++++-----------
1 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 4a17eae..9582e4e 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1040,7 +1040,6 @@ static DECLARE_WAIT_QUEUE_HEAD(command_done);
#define NO_SIGNAL (!interruptible || !signal_pending(current))
#define CALL(x) do { if ((x) == -EINTR) return -EINTR; } while (0)
-#define ECALL(x) do { if ((ret = (x))) return ret; } while (0)
#define _WAIT(x, i) CALL(ret = wait_til_done((x), i))
#define WAIT(x) _WAIT((x), interruptible)
#define IWAIT(x) _WAIT((x), 1)
@@ -3589,14 +3588,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;
@@ -3673,7 +3664,9 @@ static inline int raw_cmd_copyout(int cmd, char __user *param,
int ret;
while (ptr) {
- COPYOUT(*ptr);
+ ret = copy_to_user((void __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 &&
@@ -3722,7 +3715,9 @@ static inline int raw_cmd_copyin(int cmd, char __user *param,
if (!ptr)
return -ENOMEM;
*rcmd = ptr;
- COPYIN(*ptr);
+ ret = copy_from_user(ptr, (void __user *)param, sizeof(*ptr));
+ if (ret)
+ return -EFAULT;
ptr->next = NULL;
ptr->buffer_length = 0;
param += sizeof(struct floppy_raw_cmd);
--
1.6.6.rc0.57.gad7a
Obfuscating macros with embedded returns are not nice
Signed-off-by: Joe Perches <[email protected]>
---
drivers/block/floppy.c | 19 ++++++++-----------
1 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 9582e4e..9665ab2 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1039,11 +1039,6 @@ static DECLARE_WAIT_QUEUE_HEAD(command_done);
#define NO_SIGNAL (!interruptible || !signal_pending(current))
-#define CALL(x) do { if ((x) == -EINTR) return -EINTR; } while (0)
-#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;
@@ -2796,7 +2791,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, 1);
+ if (ret == -EINTR)
+ return -EINTR;
process_fd_request();
return ret;
}
@@ -3524,8 +3521,6 @@ static struct cont_t poll_cont = {
static int poll_drive(int interruptible, int flag)
{
- int ret;
-
/* no auto-sense, just clear dcl */
raw_cmd = &default_raw_cmd;
raw_cmd->flags = flag;
@@ -3534,8 +3529,8 @@ static int poll_drive(int interruptible, int flag)
cont = &poll_cont;
debug_dcl(DP->flags, "setting NEWCHANGE in poll_drive\n");
set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
- WAIT(floppy_ready);
- return ret;
+
+ return wait_til_done(floppy_ready, interruptible);
}
/*
@@ -3566,7 +3561,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;
--
1.6.6.rc0.57.gad7a
Various functions use int where bool is appropriate
lock_fdc, wait_til_done, poll_drive, user_reset_fdc
Convert to bool
Signed-off-by: Joe Perches <[email protected]>
---
drivers/block/floppy.c | 60 ++++++++++++++++++++++++------------------------
1 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 9665ab2..90352f6 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1387,7 +1387,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",
@@ -2548,7 +2548,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;
@@ -2774,7 +2774,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);
@@ -2791,7 +2791,7 @@ static int do_format(int drive, struct format_descr *tmp_format_req)
format_errors = 0;
cont = &format_cont;
errors = &format_errors;
- ret = wait_til_done(redo_format, 1);
+ ret = wait_til_done(redo_format, true);
if (ret == -EINTR)
return -EINTR;
process_fd_request();
@@ -3507,7 +3507,7 @@ static void do_fd_request(struct request_queue *q)
is_alive("do fd request, old request running");
return;
}
- lock_fdc(MAXTIMEOUT, 0);
+ lock_fdc(MAXTIMEOUT, false);
process_fd_request();
is_alive("do fd request");
}
@@ -3519,7 +3519,7 @@ 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)
{
/* no auto-sense, just clear dcl */
raw_cmd = &default_raw_cmd;
@@ -3550,7 +3550,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;
@@ -3791,7 +3791,7 @@ 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);
+ ret = wait_til_done(floppy_start, true);
debug_dcl(DP->flags, "calling disk change from raw_cmd ioctl\n");
if (ret != -EINTR && FDCS->reset)
@@ -3831,7 +3831,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;
}
@@ -3851,12 +3851,12 @@ 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) {
/* notice a disk change immediately, else
* we lose our settings immediately*/
- if (poll_drive(1, FD_RAW_NEED_DISK) == -EINTR)
+ if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
return -EINTR;
}
oldStretch = g->stretch;
@@ -3937,9 +3937,9 @@ 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(0, 0) == -EINTR)
+ if (poll_drive(false, 0) == -EINTR)
return -EINTR;
process_fd_request();
*g = current_type[drive];
@@ -4019,7 +4019,7 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
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
@@ -4032,7 +4032,7 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
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;
@@ -4060,9 +4060,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
return 0;
case FDFMTBEG:
- if (lock_fdc(drive, 1))
+ if (lock_fdc(drive, true))
return -EINTR;
- if (poll_drive(1, FD_RAW_NEED_DISK) == -EINTR)
+ if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
return -EINTR;
ret = UDRS->flags;
process_fd_request();
@@ -4079,7 +4079,7 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
case FDFMTEND:
case FDFLUSH:
- if (lock_fdc(drive, 1))
+ if (lock_fdc(drive, true))
return -EINTR;
return invalidate_drive(bdev);
@@ -4109,9 +4109,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
break;
case FDPOLLDRVSTAT:
- if (lock_fdc(drive, 1))
+ if (lock_fdc(drive, true))
return -EINTR;
- if (poll_drive(1, FD_RAW_NEED_DISK) == -EINTR)
+ if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
return -EINTR;
process_fd_request();
/* fall through */
@@ -4121,7 +4121,7 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
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;
@@ -4138,7 +4138,7 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
case FDRAWCMD:
if (type)
return -EINVAL;
- if (lock_fdc(drive, 1))
+ if (lock_fdc(drive, true))
return -EINTR;
set_floppy(drive);
i = raw_cmd_ioctl(cmd, (void __user *)param);
@@ -4148,7 +4148,7 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
return i;
case FDTWADDLE:
- if (lock_fdc(drive, 1))
+ if (lock_fdc(drive, true))
return -EINTR;
twaddle();
process_fd_request();
@@ -4344,8 +4344,8 @@ static int check_floppy_change(struct gendisk *disk)
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();
}
@@ -4428,7 +4428,7 @@ static int floppy_revalidate(struct gendisk *disk)
pr_info("VFS: revalidate called on non-open device.\n");
return -EFAULT;
}
- lock_fdc(drive, 0);
+ 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)) {
@@ -4449,7 +4449,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();
}
}
@@ -4851,7 +4851,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;
}
@@ -4998,7 +4998,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;
@@ -5021,7 +5021,7 @@ 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);
--
1.6.6.rc0.57.gad7a
Signed-off-by: Joe Perches <[email protected]>
---
drivers/block/floppy.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 90352f6..96b1b21 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1163,8 +1163,8 @@ static const char *timeout_message;
static void is_alive(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)) {
+ if (test_bit(0, &fdc_busy) && command_status < 2 &&
+ !timer_pending(&fd_timeout)) {
DPRINT("timeout handler died: %s\n", message);
}
}
@@ -2296,8 +2296,8 @@ 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;
--
1.6.6.rc0.57.gad7a
use it directly in the one place it's used
Signed-off-by: Joe Perches <[email protected]>
---
drivers/block/floppy.c | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 96b1b21..cc76f3d 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -250,8 +250,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 */
@@ -312,7 +310,7 @@ static int initialising = 1;
#define UFDCS (&fdc_state[FDC(drive)])
#define DPRINT(format, args...) \
- pr_info(DEVICE_NAME "%d: " format, current_drive, ##args)
+ pr_info("floppy%d: " format, current_drive, ##args)
#define PH_HEAD(floppy, head) (((((floppy)->stretch & 2) >> 1) ^ head) << 2)
#define STRETCH(floppy) ((floppy)->stretch & FD_STRETCH)
--
1.6.6.rc0.57.gad7a
Don't initialize initialized either. Default is false
Signed-off-by: Joe Perches <[email protected]>
---
drivers/block/floppy.c | 25 ++++++++++++-------------
1 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index cc76f3d..4a9cb15 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -290,13 +290,13 @@ 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))
-#define UNIT(x) ((x) & 0x03) /* drive on fdc */
+#define UNIT(x) ((x) & 0x03) /* drive on fdc */
#define FDC(x) (((x) & 0x04) >> 2) /* fdc of drive */
- /* reverse mapping from unit and fdc to drive */
+ /* reverse mapping from unit and fdc to drive */
#define REVDRIVE(fdc, unit) ((unit) + ((fdc) << 2))
#define DP (&drive_params[current_drive])
@@ -1672,7 +1672,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();
}
@@ -1699,7 +1699,7 @@ static int output_byte(char byte)
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();
@@ -1730,10 +1730,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;
@@ -2281,7 +2280,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)
@@ -2409,7 +2408,7 @@ static void floppy_shutdown(unsigned long data)
{
unsigned long flags;
- if (!initialising)
+ if (initialized)
show_floppy();
cancel_activity();
@@ -2421,7 +2420,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) {
@@ -5024,7 +5023,7 @@ static int __init floppy_init(void)
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;
--
1.6.6.rc0.57.gad7a
Used a couple of times, might simplify the code a bit.
Signed-off-by: Joe Perches <[email protected]>
---
drivers/block/floppy.c | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 4a9cb15..e054fae 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1307,6 +1307,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;
@@ -1348,8 +1354,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;
@@ -1688,7 +1696,7 @@ 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;
@@ -1748,8 +1756,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();
}
--
1.6.6.rc0.57.gad7a
And a little comment neatening
Signed-off-by: Joe Perches <[email protected]>
---
drivers/block/floppy.c | 14 ++++++++------
1 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index e054fae..7c33f61 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1814,8 +1814,7 @@ static int fdc_configure(void)
return 0;
output_byte(0);
output_byte(0x10 | (no_fifo & 0x20) | (fifo_depth & 0xf));
- output_byte(0); /* pre-compensation from track
- 0 upwards */
+ output_byte(0); /* pre-compensation from track 0 upwards */
return 1;
}
@@ -3991,9 +3990,12 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
} inparam; /* parameters coming from user space */
const char *outparam; /* parameters passed back to user space */
- /* convert compatibility eject ioctls into floppy eject ioctl.
+ /*
+ * convert compatibility eject ioctls into floppy eject ioctl.
* We do this in order to provide a means to eject floppy disks before
- * installing the new fdutils package */
+ * installing the new fdutils package,
+ * 0x6470 is SunOS floppy eject
+ */
if (cmd == CDROMEJECT || cmd == 0x6470) {
DPRINT("obsolete eject ioctl\n");
DPRINT("please use floppycontrol --eject\n");
@@ -4029,8 +4031,8 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
if (lock_fdc(drive, true))
return -EINTR;
- /* do the actual eject. Fails on
- * non-Sparc architectures */
+ /* Do the actual eject.
+ * Fails on non-Sparc architectures */
ret = fd_eject(UNIT(drive));
set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
--
1.6.6.rc0.57.gad7a
Signed-off-by: Joe Perches <[email protected]>
---
drivers/block/floppy.c | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 7c33f61..3c36302 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -2321,10 +2321,8 @@ static void recalibrate_floppy(void)
debugt("recalibrate floppy:");
do_floppy = recal_interrupt;
output_byte(FD_RECALIBRATE);
- if (UNIT(current_drive) < 0) {
+ if (UNIT(current_drive) < 0)
reset_fdc();
- return;
- }
}
/*
--
1.6.6.rc0.57.gad7a
On Tue, Dec 01, 2009 at 10:07:40PM -0800, Joe Perches wrote:
> Might as well make it cleaner...
>
> Joe Perches (13):
> drivers/block/floppy.c: Remove macro LOCK_FDC
> drivers/block/floppy.c: Add debug_dcl(...) macro
> drivers/block/floppy.c: Remove [U]CLEARF, [U]SETF, and [U]TESTF macros
> drivers/block/floppy.c: Remove most uses of CALL and ECALL macros
> drivers/block/floppy.c: remove [_]COPYIN [_]COPYOUT and ECALL macros
> drivers/block/floppy.c: remove macros CALL, WAIT and IWAIT
> drivers/block/floppy.c: convert int 1/0 to bool true/false
> drivers/block/floppy.c: Move leading && and || to preceding line
> drivers/block/floppy.c: remove #define DEVICE_NAME "floppy"
> drivers/block/floppy.c: Convert int initialising to bool initialized
> drivers/block/floppy.c: Add function is_ready_state
> drivers/block/floppy.c: Readd SunOS eject cmd comment
> drivers/block/floppy.c: Remove unnecessary return and braces
>
> drivers/block/floppy.c | 410 ++++++++++++++++++++++++------------------------
> 1 files changed, 208 insertions(+), 202 deletions(-)
>
If you want to, you can add this line to these patches:
Reviewed-by: Marcin Slusarz <[email protected]>
On Tue, 1 Dec 2009 22:07:40 -0800
Joe Perches <[email protected]> wrote:
> Might as well make it cleaner...
>
> Joe Perches (13):
> drivers/block/floppy.c: Remove macro LOCK_FDC
> drivers/block/floppy.c: Add debug_dcl(...) macro
> drivers/block/floppy.c: Remove [U]CLEARF, [U]SETF, and [U]TESTF macros
> drivers/block/floppy.c: Remove most uses of CALL and ECALL macros
> drivers/block/floppy.c: remove [_]COPYIN [_]COPYOUT and ECALL macros
> drivers/block/floppy.c: remove macros CALL, WAIT and IWAIT
> drivers/block/floppy.c: convert int 1/0 to bool true/false
> drivers/block/floppy.c: Move leading && and || to preceding line
> drivers/block/floppy.c: remove #define DEVICE_NAME "floppy"
> drivers/block/floppy.c: Convert int initialising to bool initialized
> drivers/block/floppy.c: Add function is_ready_state
> drivers/block/floppy.c: Readd SunOS eject cmd comment
> drivers/block/floppy.c: Remove unnecessary return and braces
>
> drivers/block/floppy.c | 410 ++++++++++++++++++++++++------------------------
> 1 files changed, 208 insertions(+), 202 deletions(-)
>
I like seeing it as individual patches like this, but the first batch
starts after your huge patch. Why not split that one up as well.
--
On Wed, 2009-12-02 at 11:03 -0800, Stephen Hemminger wrote:
> I like seeing it as individual patches like this, but the first batch
> starts after your huge patch. Why not split that one up as well.
I've already spent too much time doing this
for something I'll never actually use.
You can do that if you choose.
The first set is a trivial combination of
printk->pr_<foo> and some emacs macro
substitution for c99 initializations.
The second set was more logical conversions
which needed to be done piecemeal.
cheers, Joe