linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: Denis Efremov <efremov@linux.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Willy Tarreau <w@1wt.eu>
Subject: [PATCH 10/10] floppy: cleanup: expand the reply_buffer macros
Date: Mon, 24 Feb 2020 22:23:52 +0100	[thread overview]
Message-ID: <20200224212352.8640-11-w@1wt.eu> (raw)
In-Reply-To: <20200224212352.8640-1-w@1wt.eu>

Several macros were used to access reply_buffer[] at discrete positions
without making it obvious they were relying on this. These ones have
been replaced by their offset in the reply buffer to make these accesses
more obvious.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 86 +++++++++++++++++++++++++++-----------------------
 1 file changed, 47 insertions(+), 39 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 0d53335..d521899 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -341,14 +341,14 @@ static bool initialized;
 #define MAX_REPLIES 16
 static unsigned char reply_buffer[MAX_REPLIES];
 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])
-#define ST3		(reply_buffer[0])	/* result of GETSTATUS */
-#define R_TRACK		(reply_buffer[3])
-#define R_HEAD		(reply_buffer[4])
-#define R_SECTOR	(reply_buffer[5])
-#define R_SIZECODE	(reply_buffer[6])
+#define ST0		0
+#define ST1		1
+#define ST2		2
+#define ST3		0	/* result of GETSTATUS */
+#define R_TRACK		3
+#define R_HEAD		4
+#define R_SECTOR	5
+#define R_SIZECODE	6
 
 #define SEL_DLY		(2 * HZ / 100)
 
@@ -1366,34 +1366,37 @@ static int fdc_dtr(void)
 static void tell_sector(void)
 {
 	pr_cont(": track %d, head %d, sector %d, size %d",
-		R_TRACK, R_HEAD, R_SECTOR, R_SIZECODE);
+		reply_buffer[R_TRACK], reply_buffer[R_HEAD],
+		reply_buffer[R_SECTOR],
+		reply_buffer[R_SIZECODE]);
 }				/* tell_sector */
 
 static void print_errors(void)
 {
 	DPRINT("");
-	if (ST0 & ST0_ECE) {
+	if (reply_buffer[ST0] & ST0_ECE) {
 		pr_cont("Recalibrate failed!");
-	} else if (ST2 & ST2_CRC) {
+	} else if (reply_buffer[ST2] & ST2_CRC) {
 		pr_cont("data CRC error");
 		tell_sector();
-	} else if (ST1 & ST1_CRC) {
+	} else if (reply_buffer[ST1] & ST1_CRC) {
 		pr_cont("CRC error");
 		tell_sector();
-	} else if ((ST1 & (ST1_MAM | ST1_ND)) ||
-		   (ST2 & ST2_MAM)) {
+	} else if ((reply_buffer[ST1] & (ST1_MAM | ST1_ND)) ||
+		   (reply_buffer[ST2] & ST2_MAM)) {
 		if (!probing) {
 			pr_cont("sector not found");
 			tell_sector();
 		} else
 			pr_cont("probe failed...");
-	} else if (ST2 & ST2_WC) {	/* seek error */
+	} else if (reply_buffer[ST2] & ST2_WC) {	/* seek error */
 		pr_cont("wrong cylinder");
-	} else if (ST2 & ST2_BC) {	/* cylinder marked as bad */
+	} else if (reply_buffer[ST2] & ST2_BC) {	/* cylinder marked as bad */
 		pr_cont("bad cylinder");
 	} else {
 		pr_cont("unknown error. ST[0..2] are: 0x%x 0x%x 0x%x",
-			ST0, ST1, ST2);
+			reply_buffer[ST0], reply_buffer[ST1],
+			reply_buffer[ST2]);
 		tell_sector();
 	}
 	pr_cont("\n");
@@ -1417,28 +1420,28 @@ static int interpret_errors(void)
 	}
 
 	/* check IC to find cause of interrupt */
-	switch (ST0 & ST0_INTR) {
+	switch (reply_buffer[ST0] & ST0_INTR) {
 	case 0x40:		/* error occurred during command execution */
-		if (ST1 & ST1_EOC)
+		if (reply_buffer[ST1] & ST1_EOC)
 			return 0;	/* occurs with pseudo-DMA */
 		bad = 1;
-		if (ST1 & ST1_WP) {
+		if (reply_buffer[ST1] & ST1_WP) {
 			DPRINT("Drive is write protected\n");
 			clear_bit(FD_DISK_WRITABLE_BIT,
 				  &drive_state[current_drive].flags);
 			cont->done(0);
 			bad = 2;
-		} else if (ST1 & ST1_ND) {
+		} else if (reply_buffer[ST1] & ST1_ND) {
 			set_bit(FD_NEED_TWADDLE_BIT,
 				&drive_state[current_drive].flags);
-		} else if (ST1 & ST1_OR) {
+		} else if (reply_buffer[ST1] & ST1_OR) {
 			if (drive_params[current_drive].flags & FTD_MSG)
 				DPRINT("Over/Underrun - retrying\n");
 			bad = 0;
 		} else if (*errors >= drive_params[current_drive].max_errors.reporting) {
 			print_errors();
 		}
-		if (ST2 & ST2_WC || ST2 & ST2_BC)
+		if (reply_buffer[ST2] & ST2_WC || reply_buffer[ST2] & ST2_BC)
 			/* wrong cylinder => recal */
 			drive_state[current_drive].track = NEED_2_RECAL;
 		return bad;
@@ -1522,14 +1525,16 @@ static int blind_seek;
 static void seek_interrupt(void)
 {
 	debugt(__func__, "");
-	if (inr != 2 || (ST0 & 0xF8) != 0x20) {
+	if (inr != 2 || (reply_buffer[ST0] & 0xF8) != 0x20) {
 		DPRINT("seek failed\n");
 		drive_state[current_drive].track = NEED_2_RECAL;
 		cont->error();
 		cont->redo();
 		return;
 	}
-	if (drive_state[current_drive].track >= 0 && drive_state[current_drive].track != ST1 && !blind_seek) {
+	if (drive_state[current_drive].track >= 0 &&
+	    drive_state[current_drive].track != reply_buffer[ST1] &&
+	    !blind_seek) {
 		debug_dcl(drive_params[current_drive].flags,
 			  "clearing NEWCHANGE flag because of effective seek\n");
 		debug_dcl(drive_params[current_drive].flags, "jiffies=%lu\n",
@@ -1539,7 +1544,7 @@ static void seek_interrupt(void)
 					/* effective seek */
 		drive_state[current_drive].select_date = jiffies;
 	}
-	drive_state[current_drive].track = ST1;
+	drive_state[current_drive].track = reply_buffer[ST1];
 	floppy_ready();
 }
 
@@ -1559,8 +1564,8 @@ static void check_wp(void)
 		debug_dcl(drive_params[current_drive].flags,
 			  "checking whether disk is write protected\n");
 		debug_dcl(drive_params[current_drive].flags, "wp=%x\n",
-			  ST3 & 0x40);
-		if (!(ST3 & 0x40))
+			  reply_buffer[ST3] & 0x40);
+		if (!(reply_buffer[ST3] & 0x40))
 			set_bit(FD_DISK_WRITABLE_BIT,
 				&drive_state[current_drive].flags);
 		else
@@ -1634,7 +1639,7 @@ static void recal_interrupt(void)
 	debugt(__func__, "");
 	if (inr != 2)
 		fdc_state[fdc].reset = 1;
-	else if (ST0 & ST0_ECE) {
+	else if (reply_buffer[ST0] & ST0_ECE) {
 		switch (drive_state[current_drive].track) {
 		case NEED_1_RECAL:
 			debugt(__func__, "need 1 recal");
@@ -1672,7 +1677,7 @@ static void recal_interrupt(void)
 			break;
 		}
 	} else
-		drive_state[current_drive].track = ST1;
+		drive_state[current_drive].track = reply_buffer[ST1];
 	floppy_ready();
 }
 
@@ -1734,7 +1739,7 @@ irqreturn_t floppy_interrupt(int irq, void *dev_id)
 			if (do_print)
 				print_result("sensei", inr);
 			max_sensei--;
-		} while ((ST0 & 0x83) != UNIT(current_drive) &&
+		} while ((reply_buffer[ST0] & 0x83) != UNIT(current_drive) &&
 			 inr == 2 && max_sensei);
 	}
 	if (!handler) {
@@ -2292,7 +2297,7 @@ static void rw_interrupt(void)
 	int heads;
 	int nr_sectors;
 
-	if (R_HEAD >= 2) {
+	if (reply_buffer[R_HEAD] >= 2) {
 		/* some Toshiba floppy controllers occasionnally seem to
 		 * return bogus interrupts after read/write operations, which
 		 * can be recognized by a bad head number (>= 2) */
@@ -2305,7 +2310,7 @@ static void rw_interrupt(void)
 	nr_sectors = 0;
 	ssize = DIV_ROUND_UP(1 << raw_cmd->cmd[SIZECODE], 4);
 
-	if (ST1 & ST1_EOC)
+	if (reply_buffer[ST1] & ST1_EOC)
 		eoc = 1;
 	else
 		eoc = 0;
@@ -2315,17 +2320,20 @@ static void rw_interrupt(void)
 	else
 		heads = 1;
 
-	nr_sectors = (((R_TRACK - raw_cmd->cmd[TRACK]) * heads +
-		       R_HEAD - raw_cmd->cmd[HEAD]) * raw_cmd->cmd[SECT_PER_TRACK] +
-		      R_SECTOR - raw_cmd->cmd[SECTOR] + eoc) << raw_cmd->cmd[SIZECODE] >> 2;
+	nr_sectors = (((reply_buffer[R_TRACK] - raw_cmd->cmd[TRACK]) * heads +
+		       reply_buffer[R_HEAD] - raw_cmd->cmd[HEAD]) * raw_cmd->cmd[SECT_PER_TRACK] +
+		      reply_buffer[R_SECTOR] - raw_cmd->cmd[SECTOR] + eoc) << raw_cmd->cmd[SIZECODE] >> 2;
 
 	if (nr_sectors / ssize >
 	    DIV_ROUND_UP(in_sector_offset + current_count_sectors, ssize)) {
 		DPRINT("long rw: %x instead of %lx\n",
 		       nr_sectors, current_count_sectors);
-		pr_info("rs=%d s=%d\n", R_SECTOR, raw_cmd->cmd[SECTOR]);
-		pr_info("rh=%d h=%d\n", R_HEAD, raw_cmd->cmd[HEAD]);
-		pr_info("rt=%d t=%d\n", R_TRACK, raw_cmd->cmd[TRACK]);
+		pr_info("rs=%d s=%d\n", reply_buffer[R_SECTOR],
+			raw_cmd->cmd[SECTOR]);
+		pr_info("rh=%d h=%d\n", reply_buffer[R_HEAD],
+			raw_cmd->cmd[HEAD]);
+		pr_info("rt=%d t=%d\n", reply_buffer[R_TRACK],
+			raw_cmd->cmd[TRACK]);
 		pr_info("heads=%d eoc=%d\n", heads, eoc);
 		pr_info("spt=%d st=%d ss=%d\n",
 			raw_cmd->cmd[SECT_PER_TRACK], fsector_t, ssize);
-- 
2.9.0


  parent reply	other threads:[~2020-02-24 21:40 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-24 21:23 [PATCH 00/10] floppy driver cleanups (deobfuscation) Willy Tarreau
2020-02-24 21:23 ` [PATCH 01/10] floppy: cleanup: expand macro FDCS Willy Tarreau
2020-02-24 21:53   ` Linus Torvalds
2020-02-24 23:13     ` Denis Efremov
2020-02-25  3:45       ` Willy Tarreau
2020-02-25  7:14         ` Denis Efremov
2020-02-25 14:02           ` Willy Tarreau
2020-02-25 15:22             ` Denis Efremov
2020-02-25 15:39               ` Denis Efremov
2020-02-25 16:12                 ` Willy Tarreau
2020-02-25 18:02               ` Willy Tarreau
2020-02-25 18:08                 ` Willy Tarreau
2020-02-25 18:08               ` Linus Torvalds
2020-02-25 18:15                 ` Willy Tarreau
2020-02-25 18:27                   ` Linus Torvalds
2020-02-26  8:18                 ` Willy Tarreau
2020-02-25 11:37   ` Denis Efremov
2020-02-24 21:23 ` [PATCH 02/10] floppy: cleanup: expand macro UFDCS Willy Tarreau
2020-02-24 21:23 ` [PATCH 03/10] floppy: cleanup: expand macro UDP Willy Tarreau
2020-02-24 21:23 ` [PATCH 04/10] floppy: cleanup: expand macro UDRS Willy Tarreau
2020-02-24 21:23 ` [PATCH 05/10] floppy: cleanup: expand macro UDRWE Willy Tarreau
2020-02-24 21:23 ` [PATCH 06/10] floppy: cleanup: expand macro DP Willy Tarreau
2020-02-24 21:23 ` [PATCH 07/10] floppy: cleanup: expand macro DRS Willy Tarreau
2020-02-24 21:23 ` [PATCH 08/10] floppy: cleanup: expand macro DRWE Willy Tarreau
2020-02-24 21:23 ` [PATCH 09/10] floppy: cleanup: expand the R/W / format command macros Willy Tarreau
2020-02-24 21:23 ` Willy Tarreau [this message]
2020-02-26  8:07 ` [PATCH 11/16] floppy: remove dead code for drives scanning on ARM Willy Tarreau
2020-02-26  8:07   ` [PATCH 12/16] floppy: remove incomplete support for second FDC from ARM code Willy Tarreau
2020-02-29 16:38     ` Denis Efremov
2020-02-26  8:07   ` [PATCH 13/16] floppy: prepare ARM code to simplify base address separation Willy Tarreau
2020-02-26  8:07   ` [PATCH 14/16] floppy: introduce new functions fdc_inb() and fdc_outb() Willy Tarreau
2020-02-26  8:07   ` [PATCH 15/16] floppy: separate the FDC's base address from its registers Willy Tarreau
2020-02-26 15:36     ` Denis Efremov
2020-02-26 15:46       ` Willy Tarreau
2020-02-26  8:07   ` [PATCH 16/16] floppy: rename the global "fdc" variable to "current_fdc" Willy Tarreau
2020-03-01  8:21   ` [PATCH 11/16] floppy: remove dead code for drives scanning on ARM Denis Efremov
2020-03-01  8:59     ` Willy Tarreau
2020-02-26 14:57 ` [PATCH 00/10] floppy driver cleanups (deobfuscation) Denis Efremov
2020-02-26 17:49   ` Linus Torvalds
2020-02-26 18:41     ` Willy Tarreau
2020-02-29 14:13     ` Willy Tarreau
2020-02-29 15:58       ` Linus Torvalds
2020-02-29 23:19         ` Ondrej Zary
2020-03-01  6:46           ` Willy Tarreau
2020-03-01 17:01             ` Ondrej Zary

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200224212352.8640-11-w@1wt.eu \
    --to=w@1wt.eu \
    --cc=axboe@kernel.dk \
    --cc=efremov@linux.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).