Skip to contentSkip to conversation

floppy driver cleanup

PATCH In review Randy.Dunlap 3 participants 3 messages Aug 28, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 floppy driver cleanup

Hi,

I'm looking into some oopsen that happen in bad_flp_intr() [1] but noticed that the floppy driver needs some cleaning.

Please apply.

[1]
http://marc.theaimsgroup.com/?l=linux-kernel&m=105837886921297&w=2
http://marc.theaimsgroup.com/?l=linux-kernel&m=105988913707536&w=2
and my home machine (with some bad media)

--
~Randy

patch_name: floppy_update.patch
patch_version: 2003-08-27.22:32:00
author: Randy.Dunlap <[email protected]>

description:	use kernel.h min() and max();
		use C99 initializers;
		clean up some odd function calls [(void *)(void *)];

product: Linux
product_versions: 260-826
maintainer: _
diffstat: =

 drivers/block/floppy.c |  112 ++++++++++++++++++++++---------------------------
 1 files changed, 51 insertions(+), 61 deletions(-)
drivers/block/floppy.c renamed from drivers/block/floppy.c~badio +51 -61
diff -Naur ./drivers/block/floppy.c~badio ./drivers/block/floppy.c
@@ -695,23 +695,9 @@
 	spin_unlock_irqrestore(&floppy_lock, flags);
 }
 
-static int maximum(int a, int b)
-{
-	if (a > b)
-		return a;
-	else
-		return b;
-}
-#define INFBOUND(a,b) (a)=maximum((a),(b));
+#define INFBOUND(a,b) (a)=max_t(int, a, b)
 
-static int minimum(int a, int b)
-{
-	if (a < b)
-		return a;
-	else
-		return b;
-}
-#define SUPBOUND(a,b) (a)=minimum((a),(b));
+#define SUPBOUND(a,b) (a)=min_t(int, a, b)
 
 
 /*
@@ -1021,7 +1007,7 @@
 
 static DECLARE_WORK(floppy_work, NULL, NULL);
 
-static void schedule_bh( void (*handler)(void*) )
+static void schedule_bh(void (*handler) (void *))
 {
 	PREPARE_WORK(&floppy_work, handler, NULL);
 	schedule_work(&floppy_work);
@@ -1035,7 +1021,7 @@
 
 	spin_lock_irqsave(&floppy_lock, flags);
 	do_floppy = NULL;
-	PREPARE_WORK(&floppy_work, (void*)(void*)empty, NULL);
+	PREPARE_WORK(&floppy_work, (void*)empty, NULL);
 	del_timer(&fd_timer);
 	spin_unlock_irqrestore(&floppy_lock, flags);
 }
@@ -1814,7 +1800,7 @@
 		} while ((ST0 & 0x83) != UNIT(current_drive) && inr == 2 && max_sensei);
 	}
 	if (handler) {
-		schedule_bh( (void *)(void *) handler);
+		schedule_bh((void *) handler);
 	} else
 		FDCS->reset = 1;
 	is_alive("normal interrupt end");
@@ -2058,26 +2044,26 @@
 	wake_up(&command_done);
 }
 
-static struct cont_t wakeup_cont={
-	empty,
-	do_wakeup,
-	empty,
-	(done_f)empty
+static struct cont_t wakeup_cont = {
+	.interrupt = empty,
+	.redo = do_wakeup,
+	.error = empty,
+	.done = (done_f) empty
 };
 
 
-static struct cont_t intr_cont={
-	empty,
-	process_fd_request,
-	empty,
-	(done_f) empty
+static struct cont_t intr_cont = {
+	.interrupt = empty,
+	.redo = process_fd_request,
+	.error = empty,
+	.done = (done_f) empty
 };
 
 static int wait_til_done(void (*handler)(void), int interruptible)
 {
 	int ret;
 
-	schedule_bh((void *)(void *)handler);
+	schedule_bh((void *) handler);
 
 	if (command_status < 2 && NO_SIGNAL) {
 		DECLARE_WAITQUEUE(wait, current);
@@ -2281,11 +2267,12 @@
 #endif
 }
 
-static struct cont_t format_cont={
-	format_interrupt,
-	redo_format,
-	bad_flp_intr,
-	generic_done };
+static struct cont_t format_cont = {
+	.interrupt = format_interrupt,
+	.redo = redo_format,
+	.error = bad_flp_intr,
+	.done = generic_done
+};
 
 static int do_format(int drive, struct format_descr *tmp_format_req)
 {
@@ -2523,12 +2510,12 @@
 	int size, i;
 
 	max_sector = transfer_size(ssize,
-				   minimum(max_sector, max_sector_2),
+				   min(max_sector, max_sector_2),
 				   current_req->nr_sectors);
 
 	if (current_count_sectors <= 0 && CT(COMMAND) == FD_WRITE &&
 	    buffer_max > fsector_t + current_req->nr_sectors)
-		current_count_sectors = minimum(buffer_max - fsector_t,
+		current_count_sectors = min_t(int, buffer_max - fsector_t,
 						current_req->nr_sectors);
 
 	remaining = current_count_sectors << 9;
@@ -2546,7 +2533,7 @@
 	}
 #endif
 
-	buffer_max = maximum(max_sector, buffer_max);
+	buffer_max = max(max_sector, buffer_max);
 
 	dma_buffer = floppy_track_buffer + ((fsector_t - buffer_min) << 9);
 
@@ -2697,7 +2684,7 @@
 	if ((_floppy->rate & FD_2M) && (!TRACK) && (!HEAD)){
 		max_sector = 2 * _floppy->sect / 3;
 		if (fsector_t >= max_sector){
-			current_count_sectors = minimum(_floppy->sect - fsector_t,
+			current_count_sectors = min_t(int, _floppy->sect - fsector_t,
 							current_req->nr_sectors);
 			return 1;
 		}
@@ -2987,7 +2974,7 @@
 
 		if (TESTF(FD_NEED_TWADDLE))
 			twaddle();
-		schedule_bh( (void *)(void *) floppy_start);
+		schedule_bh((void *) floppy_start);
 #ifdef DEBUGT
 		debugt("queue fd request");
 #endif
@@ -2996,16 +2983,17 @@
 #undef REPEAT
 }
 
-static struct cont_t rw_cont={
-	rw_interrupt,
-	redo_fd_request,
-	bad_flp_intr,
-	request_done };
+static struct cont_t rw_cont = {
+	.interrupt = rw_interrupt,
+	.redo = redo_fd_request,
+	.error = bad_flp_intr,
+	.done = request_done
+};
 
 static void process_fd_request(void)
 {
 	cont = &rw_cont;
-	schedule_bh( (void *)(void *) redo_fd_request);
+	schedule_bh((void *) redo_fd_request);
 }
 
 static void do_fd_request(request_queue_t * q)
@@ -3031,11 +3019,12 @@
 	is_alive("do fd request");
 }
 
-static struct cont_t poll_cont={
-	success_and_wakeup,
-	floppy_ready,
-	generic_failure,
-	generic_done };
+static struct cont_t poll_cont = {
+	.interrupt = success_and_wakeup,
+	.redo = floppy_ready,
+	.error = generic_failure,
+	.done = generic_done
+};
 
 static int poll_drive(int interruptible, int flag)
 {
@@ -3066,11 +3055,12 @@
 	printk("weird, reset interrupt called\n");
 }
 
-static struct cont_t reset_cont={
-	reset_intr,
-	success_and_wakeup,
-	generic_failure,
-	generic_done };
+static struct cont_t reset_cont = {
+	.interrupt = reset_intr,
+	. redo = success_and_wakeup,
+	. error = generic_failure,
+	. done = generic_done
+};
 
 static int user_reset_fdc(int drive, int arg, int interruptible)
 {
@@ -3174,11 +3164,11 @@
 }
 
 
-static struct cont_t raw_cmd_cont={
-	success_and_wakeup,
-	floppy_start,
-	generic_failure,
-	raw_cmd_done
+static struct cont_t raw_cmd_cont = {
+	.interrupt = success_and_wakeup,
+	.redo = floppy_start,
+	.error = generic_failure,
+	.done = raw_cmd_done
 };
 
 static inline int raw_cmd_copyout(int cmd, char *param,
#1 lore raw
Quoted 2 lines · Randy.Dunlap
drivers/block/floppy.c renamed from drivers/block/floppy.c~badio +1 -1
-static void schedule_bh( void (*handler)(void*) )
+static void schedule_bh(void (*handler) (void *))

...

Quoted 2 lines
drivers/block/floppy.c renamed from drivers/block/floppy.c~badio +1 -1
-		schedule_bh( (void *)(void *) handler);
+		schedule_bh((void *) handler);

...

Quoted 2 lines
drivers/block/floppy.c renamed from drivers/block/floppy.c~badio +1 -1
-	schedule_bh((void *)(void *)handler);
+	schedule_bh((void *) handler);

...

Quoted 2 lines
drivers/block/floppy.c renamed from drivers/block/floppy.c~badio +1 -1
-		schedule_bh( (void *)(void *) floppy_start);
+		schedule_bh((void *) floppy_start);

...

drivers/block/floppy.c line 2996

Quoted 2 lines
drivers/block/floppy.c renamed from drivers/block/floppy.c~badio +1 -1
-	schedule_bh( (void *)(void *) redo_fd_request);
+	schedule_bh((void *) redo_fd_request);

Am I the only one having problems with code like this? (Not Randy's, the original.)

1. void* and function pointers are not interchangeable. The casts should be to (void(*)(void*)) not (void*).

2. If shedule_bh() causes handler to be invoked as a (void(*)(void*)), then handler had better point to a function with exactly that prototype and nothing else. Fixing this also eliminates the need for the casts.

IMO changing whitespace while these issues remain is just a waste of time.

/Mikael

#2 lore raw
Quoted 11 lines · Mikael Pettersson
Quoted 2 lines · Randy.Dunlap
(quoted diff) +1 -1
-static void schedule_bh( void (*handler)(void*) )
+static void schedule_bh(void (*handler) (void *))

...

Quoted 2 lines
(quoted diff) +1 -1
-		schedule_bh( (void *)(void *) handler);
+		schedule_bh((void *) handler);

...

Quoted 2 lines
(quoted diff) +1 -1
-	schedule_bh((void *)(void *)handler);
+	schedule_bh((void *) handler);

...

Quoted 8 lines
Quoted 2 lines
(quoted diff) +1 -1
-		schedule_bh( (void *)(void *) floppy_start);
+		schedule_bh((void *) floppy_start);

...

Review

Quoted 2 lines
(quoted diff) +1 -1
-	schedule_bh( (void *)(void *) redo_fd_request);
+	schedule_bh((void *) redo_fd_request);

Am I the only one having problems with code like this? (Not Randy's, the original.)

No, you're not - I also instapuked over that.

drivers/block/floppy.c renamed from drivers/block/floppy.c~floppy-more-cleanup +11 -11
diff -puN drivers/block/floppy.c~floppy-more-cleanup drivers/block/floppy.c
@@ -1007,9 +1007,9 @@ static void empty(void)
 
 static DECLARE_WORK(floppy_work, NULL, NULL);
 
-static void schedule_bh(void (*handler) (void *))
+static void schedule_bh(void (*handler) (void))
 {
-	PREPARE_WORK(&floppy_work, handler, NULL);
+	PREPARE_WORK(&floppy_work, (void (*)(void *))handler, NULL);
 	schedule_work(&floppy_work);
 }
 
@@ -1799,9 +1799,9 @@ irqreturn_t floppy_interrupt(int irq, vo
 			max_sensei--;
 		} while ((ST0 & 0x83) != UNIT(current_drive) && inr == 2 && max_sensei);
 	}
-	if (handler) {
-		schedule_bh((void *) handler);
-	} else
+	if (handler)
+		schedule_bh(handler);
+	else
 		FDCS->reset = 1;
 	is_alive("normal interrupt end");
 
@@ -2063,7 +2063,7 @@ static int wait_til_done(void (*handler)
 {
 	int ret;
 
-	schedule_bh((void *) handler);
+	schedule_bh(handler);
 
 	if (command_status < 2 && NO_SIGNAL) {
 		DECLARE_WAITQUEUE(wait, current);
@@ -2974,7 +2974,7 @@ static void redo_fd_request(void)
 
 		if (TESTF(FD_NEED_TWADDLE))
 			twaddle();
-		schedule_bh((void *) floppy_start);
+		schedule_bh(floppy_start);
 #ifdef DEBUGT
 		debugt("queue fd request");
 #endif
@@ -2993,7 +2993,7 @@ static struct cont_t rw_cont = {
 static void process_fd_request(void)
 {
 	cont = &rw_cont;
-	schedule_bh((void *) redo_fd_request);
+	schedule_bh(redo_fd_request);
 }
 
 static void do_fd_request(request_queue_t * q)
@@ -3057,9 +3057,9 @@ static void reset_intr(void)
 
 static struct cont_t reset_cont = {
 	.interrupt = reset_intr,
-	. redo = success_and_wakeup,
-	. error = generic_failure,
-	. done = generic_done
+	.redo = success_and_wakeup,
+	.error = generic_failure,
+	.done = generic_done
 };
 
 static int user_reset_fdc(int drive, int arg, int interruptible)

_