Commit 1230e437 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] mcdx.c insanity removal

The mcdx.c author had pulled off something absolutely amazing - he had
declared several unsigned variables (ISA port numbers) as void *, using
explicit cast to unsigned in almost all places that used them. 
Exception: printk.  There he proudly used them as pointers - with %3p in
format.  That cute trick allowed him to avoid using %03x, which
apparently scared him for some reason. 

Switched to use of unsigned, killed casts, replaced %3p with %03x in
formats.  BTW, the code had been that way since the initial merge back
in 1.3.7...
parent 661c8e51
...@@ -81,10 +81,6 @@ static const char *mcdx_c_version ...@@ -81,10 +81,6 @@ static const char *mcdx_c_version
#define mcdx_drive_map mcdx #define mcdx_drive_map mcdx
#include "mcdx.h" #include "mcdx.h"
#if BITS_PER_LONG != 32
# error FIXME: this driver only works on 32-bit platforms
#endif
#ifndef HZ #ifndef HZ
#error HZ not defined #error HZ not defined
#endif #endif
...@@ -189,12 +185,12 @@ struct s_drive_stuff { ...@@ -189,12 +185,12 @@ struct s_drive_stuff {
#endif /* AK2 */ #endif /* AK2 */
/* adds and odds */ /* adds and odds */
void *wreg_data; /* w data */ unsigned wreg_data; /* w data */
void *wreg_reset; /* w hardware reset */ unsigned wreg_reset; /* w hardware reset */
void *wreg_hcon; /* w hardware conf */ unsigned wreg_hcon; /* w hardware conf */
void *wreg_chn; /* w channel */ unsigned wreg_chn; /* w channel */
void *rreg_data; /* r data */ unsigned rreg_data; /* r data */
void *rreg_status; /* r status */ unsigned rreg_status; /* r status */
int irq; /* irq used by this drive */ int irq; /* irq used by this drive */
int present; /* drive present and its capabilities */ int present; /* drive present and its capabilities */
...@@ -274,7 +270,7 @@ static void log2msf(unsigned int, struct cdrom_msf0 *); ...@@ -274,7 +270,7 @@ static void log2msf(unsigned int, struct cdrom_msf0 *);
static unsigned int msf2log(const struct cdrom_msf0 *); static unsigned int msf2log(const struct cdrom_msf0 *);
static unsigned int uint2bcd(unsigned int); static unsigned int uint2bcd(unsigned int);
static unsigned int bcd2uint(unsigned char); static unsigned int bcd2uint(unsigned char);
static char *port(int *); static unsigned port(int *);
static int irq(int *); static int irq(int *);
static void mcdx_delay(struct s_drive_stuff *, long jifs); static void mcdx_delay(struct s_drive_stuff *, long jifs);
static int mcdx_transfer(struct s_drive_stuff *, char *buf, int sector, static int mcdx_transfer(struct s_drive_stuff *, char *buf, int sector,
...@@ -868,7 +864,7 @@ static irqreturn_t mcdx_intr(int irq, void *dev_id, struct pt_regs *regs) ...@@ -868,7 +864,7 @@ static irqreturn_t mcdx_intr(int irq, void *dev_id, struct pt_regs *regs)
#endif /* AK2 */ #endif /* AK2 */
/* get the interrupt status */ /* get the interrupt status */
b = inb((unsigned int) stuffp->rreg_status); b = inb(stuffp->rreg_status);
stuffp->introk = ~b & MCDX_RBIT_DTEN; stuffp->introk = ~b & MCDX_RBIT_DTEN;
/* NOTE: We only should get interrupts if the data we /* NOTE: We only should get interrupts if the data we
...@@ -882,7 +878,7 @@ static irqreturn_t mcdx_intr(int irq, void *dev_id, struct pt_regs *regs) ...@@ -882,7 +878,7 @@ static irqreturn_t mcdx_intr(int irq, void *dev_id, struct pt_regs *regs)
xtrace(IRQ, "intr() irq %d hw status 0x%02x\n", irq, b); xtrace(IRQ, "intr() irq %d hw status 0x%02x\n", irq, b);
if (~b & MCDX_RBIT_STEN) { if (~b & MCDX_RBIT_STEN) {
xinfo("intr() irq %d status 0x%02x\n", xinfo("intr() irq %d status 0x%02x\n",
irq, inb((unsigned int) stuffp->rreg_data)); irq, inb(stuffp->rreg_data));
} else { } else {
xinfo("intr() irq %d ambiguous hw status\n", irq); xinfo("intr() irq %d ambiguous hw status\n", irq);
} }
...@@ -945,7 +941,7 @@ static int mcdx_talk(struct s_drive_stuff *stuffp, ...@@ -945,7 +941,7 @@ static int mcdx_talk(struct s_drive_stuff *stuffp,
char *bp = (char *) buffer; char *bp = (char *) buffer;
size_t sz = size; size_t sz = size;
outsb((unsigned int) stuffp->wreg_data, cmd, cmdlen); outsb(stuffp->wreg_data, cmd, cmdlen);
xtrace(TALK, "talk() command sent\n"); xtrace(TALK, "talk() command sent\n");
/* get the status byte */ /* get the status byte */
...@@ -1049,8 +1045,7 @@ void __exit mcdx_exit(void) ...@@ -1049,8 +1045,7 @@ void __exit mcdx_exit(void)
continue; continue;
} }
put_disk(stuffp->disk); put_disk(stuffp->disk);
release_region((unsigned long) stuffp->wreg_data, release_region(stuffp->wreg_data, MCDX_IO_SIZE);
MCDX_IO_SIZE);
free_irq(stuffp->irq, NULL); free_irq(stuffp->irq, NULL);
if (stuffp->toc) { if (stuffp->toc) {
xtrace(MALLOC, "cleanup_module() free toc @ %p\n", xtrace(MALLOC, "cleanup_module() free toc @ %p\n",
...@@ -1116,8 +1111,7 @@ int __init mcdx_init_drive(int drive) ...@@ -1116,8 +1111,7 @@ int __init mcdx_init_drive(int drive)
/* setup our irq and i/o addresses */ /* setup our irq and i/o addresses */
stuffp->irq = irq(mcdx_drive_map[drive]); stuffp->irq = irq(mcdx_drive_map[drive]);
stuffp->wreg_data = stuffp->rreg_data = stuffp->wreg_data = stuffp->rreg_data = port(mcdx_drive_map[drive]);
port(mcdx_drive_map[drive]);
stuffp->wreg_reset = stuffp->rreg_status = stuffp->wreg_data + 1; stuffp->wreg_reset = stuffp->rreg_status = stuffp->wreg_data + 1;
stuffp->wreg_hcon = stuffp->wreg_reset + 1; stuffp->wreg_hcon = stuffp->wreg_reset + 1;
stuffp->wreg_chn = stuffp->wreg_hcon + 1; stuffp->wreg_chn = stuffp->wreg_hcon + 1;
...@@ -1127,10 +1121,9 @@ int __init mcdx_init_drive(int drive) ...@@ -1127,10 +1121,9 @@ int __init mcdx_init_drive(int drive)
init_waitqueue_head(&stuffp->sleepq); init_waitqueue_head(&stuffp->sleepq);
/* check if i/o addresses are available */ /* check if i/o addresses are available */
if (!request_region((unsigned int) stuffp->wreg_data, MCDX_IO_SIZE, if (!request_region(stuffp->wreg_data, MCDX_IO_SIZE, "mcdx")) {
"mcdx")) { xwarn("0x%03x,%d: Init failed. "
xwarn("0x%3p,%d: Init failed. " "I/O ports (0x%03x..0x%03x) already in use.\n",
"I/O ports (0x%3p..0x%3p) already in use.\n",
stuffp->wreg_data, stuffp->irq, stuffp->wreg_data, stuffp->irq,
stuffp->wreg_data, stuffp->wreg_data,
stuffp->wreg_data + MCDX_IO_SIZE - 1); stuffp->wreg_data + MCDX_IO_SIZE - 1);
...@@ -1141,7 +1134,7 @@ int __init mcdx_init_drive(int drive) ...@@ -1141,7 +1134,7 @@ int __init mcdx_init_drive(int drive)
return 0; /* next drive */ return 0; /* next drive */
} }
xtrace(INIT, "init() i/o port is available at 0x%3p\n", xtrace(INIT, "init() i/o port is available at 0x%03x\n"
stuffp->wreg_data); stuffp->wreg_data);
xtrace(INIT, "init() hardware reset\n"); xtrace(INIT, "init() hardware reset\n");
mcdx_reset(stuffp, HARD, 1); mcdx_reset(stuffp, HARD, 1);
...@@ -1149,9 +1142,8 @@ int __init mcdx_init_drive(int drive) ...@@ -1149,9 +1142,8 @@ int __init mcdx_init_drive(int drive)
xtrace(INIT, "init() get version\n"); xtrace(INIT, "init() get version\n");
if (-1 == mcdx_requestversion(stuffp, &version, 4)) { if (-1 == mcdx_requestversion(stuffp, &version, 4)) {
/* failed, next drive */ /* failed, next drive */
release_region((unsigned long) stuffp->wreg_data, release_region(stuffp->wreg_data, MCDX_IO_SIZE);
MCDX_IO_SIZE); xwarn("%s=0x%03x,%d: Init failed. Can't get version.\n",
xwarn("%s=0x%3p,%d: Init failed. Can't get version.\n",
MCDX, stuffp->wreg_data, stuffp->irq); MCDX, stuffp->wreg_data, stuffp->irq);
xtrace(MALLOC, "init() free stuffp @ %p\n", stuffp); xtrace(MALLOC, "init() free stuffp @ %p\n", stuffp);
kfree(stuffp); kfree(stuffp);
...@@ -1181,9 +1173,8 @@ int __init mcdx_init_drive(int drive) ...@@ -1181,9 +1173,8 @@ int __init mcdx_init_drive(int drive)
stuffp->playcmd = READ1X; stuffp->playcmd = READ1X;
if (!stuffp->present) { if (!stuffp->present) {
release_region((unsigned long) stuffp->wreg_data, release_region(stuffp->wreg_data, MCDX_IO_SIZE);
MCDX_IO_SIZE); xwarn("%s=0x%03x,%d: Init failed. No Mitsumi CD-ROM?.\n",
xwarn("%s=0x%3p,%d: Init failed. No Mitsumi CD-ROM?.\n",
MCDX, stuffp->wreg_data, stuffp->irq); MCDX, stuffp->wreg_data, stuffp->irq);
kfree(stuffp); kfree(stuffp);
put_disk(disk); put_disk(disk);
...@@ -1192,8 +1183,7 @@ int __init mcdx_init_drive(int drive) ...@@ -1192,8 +1183,7 @@ int __init mcdx_init_drive(int drive)
xtrace(INIT, "init() register blkdev\n"); xtrace(INIT, "init() register blkdev\n");
if (register_blkdev(MAJOR_NR, "mcdx")) { if (register_blkdev(MAJOR_NR, "mcdx")) {
release_region((unsigned long) stuffp->wreg_data, release_region(stuffp->wreg_data, MCDX_IO_SIZE);
MCDX_IO_SIZE);
kfree(stuffp); kfree(stuffp);
put_disk(disk); put_disk(disk);
return 1; return 1;
...@@ -1202,8 +1192,7 @@ int __init mcdx_init_drive(int drive) ...@@ -1202,8 +1192,7 @@ int __init mcdx_init_drive(int drive)
mcdx_queue = blk_init_queue(do_mcdx_request, &mcdx_lock); mcdx_queue = blk_init_queue(do_mcdx_request, &mcdx_lock);
if (!mcdx_queue) { if (!mcdx_queue) {
unregister_blkdev(MAJOR_NR, "mcdx"); unregister_blkdev(MAJOR_NR, "mcdx");
release_region((unsigned long) stuffp->wreg_data, release_region(stuffp->wreg_data, MCDX_IO_SIZE);
MCDX_IO_SIZE);
kfree(stuffp); kfree(stuffp);
put_disk(disk); put_disk(disk);
return 1; return 1;
...@@ -1212,9 +1201,8 @@ int __init mcdx_init_drive(int drive) ...@@ -1212,9 +1201,8 @@ int __init mcdx_init_drive(int drive)
xtrace(INIT, "init() subscribe irq and i/o\n"); xtrace(INIT, "init() subscribe irq and i/o\n");
mcdx_irq_map[stuffp->irq] = stuffp; mcdx_irq_map[stuffp->irq] = stuffp;
if (request_irq(stuffp->irq, mcdx_intr, SA_INTERRUPT, "mcdx", NULL)) { if (request_irq(stuffp->irq, mcdx_intr, SA_INTERRUPT, "mcdx", NULL)) {
release_region((unsigned long) stuffp->wreg_data, release_region(stuffp->wreg_data, MCDX_IO_SIZE);
MCDX_IO_SIZE); xwarn("%s=0x%03x,%d: Init failed. Can't get irq (%d).\n",
xwarn("%s=0x%3p,%d: Init failed. Can't get irq (%d).\n",
MCDX, stuffp->wreg_data, stuffp->irq, stuffp->irq); MCDX, stuffp->wreg_data, stuffp->irq, stuffp->irq);
stuffp->irq = 0; stuffp->irq = 0;
blk_cleanup_queue(mcdx_queue); blk_cleanup_queue(mcdx_queue);
...@@ -1228,13 +1216,13 @@ int __init mcdx_init_drive(int drive) ...@@ -1228,13 +1216,13 @@ int __init mcdx_init_drive(int drive)
int i; int i;
mcdx_delay(stuffp, HZ / 2); mcdx_delay(stuffp, HZ / 2);
for (i = 100; i; i--) for (i = 100; i; i--)
(void) inb((unsigned int) stuffp->rreg_status); (void) inb(stuffp->rreg_status);
} }
#if WE_KNOW_WHY #if WE_KNOW_WHY
/* irq 11 -> channel register */ /* irq 11 -> channel register */
outb(0x50, (unsigned int) stuffp->wreg_chn); outb(0x50, stuffp->wreg_chn);
#endif #endif
xtrace(INIT, "init() set non dma but irq mode\n"); xtrace(INIT, "init() set non dma but irq mode\n");
...@@ -1252,15 +1240,14 @@ int __init mcdx_init_drive(int drive) ...@@ -1252,15 +1240,14 @@ int __init mcdx_init_drive(int drive)
disk->flags = GENHD_FL_CD; disk->flags = GENHD_FL_CD;
stuffp->disk = disk; stuffp->disk = disk;
sprintf(msg, " mcdx: Mitsumi CD-ROM installed at 0x%3p, irq %d." sprintf(msg, " mcdx: Mitsumi CD-ROM installed at 0x%03x, irq %d."
" (Firmware version %c %x)\n", " (Firmware version %c %x)\n",
stuffp->wreg_data, stuffp->irq, version.code, version.ver); stuffp->wreg_data, stuffp->irq, version.code, version.ver);
mcdx_stuffp[drive] = stuffp; mcdx_stuffp[drive] = stuffp;
xtrace(INIT, "init() mcdx_stuffp[%d] = %p\n", drive, stuffp); xtrace(INIT, "init() mcdx_stuffp[%d] = %p\n", drive, stuffp);
if (register_cdrom(&stuffp->info) != 0) { if (register_cdrom(&stuffp->info) != 0) {
printk("Cannot register Mitsumi CD-ROM!\n"); printk("Cannot register Mitsumi CD-ROM!\n");
release_region((unsigned long) stuffp->wreg_data, release_region(stuffp->wreg_data, MCDX_IO_SIZE);
MCDX_IO_SIZE);
free_irq(stuffp->irq, NULL); free_irq(stuffp->irq, NULL);
kfree(stuffp); kfree(stuffp);
put_disk(disk); put_disk(disk);
...@@ -1413,19 +1400,17 @@ static int mcdx_xfer(struct s_drive_stuff *stuffp, ...@@ -1413,19 +1400,17 @@ static int mcdx_xfer(struct s_drive_stuff *stuffp,
const int HEAD = const int HEAD =
CD_FRAMESIZE_RAW - CD_XA_TAIL - CD_FRAMESIZE_RAW - CD_XA_TAIL -
CD_FRAMESIZE; CD_FRAMESIZE;
insb((unsigned int) stuffp->rreg_data, p, insb(stuffp->rreg_data, p, HEAD);
HEAD);
} }
/* now actually read the data */ /* now actually read the data */
insb((unsigned int) stuffp->rreg_data, p, 512); insb(stuffp->rreg_data, p, 512);
/* test if it's the last sector of a block, /* test if it's the last sector of a block,
* if so, we have to handle XA special */ * if so, we have to handle XA special */
if ((3 == (stuffp->pending & 3)) && stuffp->xa) { if ((3 == (stuffp->pending & 3)) && stuffp->xa) {
char dummy[CD_XA_TAIL]; char dummy[CD_XA_TAIL];
insb((unsigned int) stuffp->rreg_data, insb(stuffp->rreg_data, &dummy[0], CD_XA_TAIL);
&dummy[0], CD_XA_TAIL);
} }
if (stuffp->pending == sector) { if (stuffp->pending == sector) {
...@@ -1493,7 +1478,7 @@ static int mcdx_xfer(struct s_drive_stuff *stuffp, ...@@ -1493,7 +1478,7 @@ static int mcdx_xfer(struct s_drive_stuff *stuffp,
stuffp->busy = 1; stuffp->busy = 1;
/* Now really issue the request command */ /* Now really issue the request command */
outsb((unsigned int) stuffp->wreg_data, cmd, sizeof cmd); outsb(stuffp->wreg_data, cmd, sizeof cmd);
} }
#ifdef AK2 #ifdef AK2
...@@ -1514,9 +1499,9 @@ static int mcdx_xfer(struct s_drive_stuff *stuffp, ...@@ -1514,9 +1499,9 @@ static int mcdx_xfer(struct s_drive_stuff *stuffp,
/* Access to elements of the mcdx_drive_map members */ /* Access to elements of the mcdx_drive_map members */
static char *port(int *ip) static unsigned port(int *ip)
{ {
return (char *) ip[0]; return ip[0];
} }
static int irq(int *ip) static int irq(int *ip)
{ {
...@@ -1682,7 +1667,7 @@ mcdx_playmsf(struct s_drive_stuff *stuffp, const struct cdrom_msf *msf) ...@@ -1682,7 +1667,7 @@ mcdx_playmsf(struct s_drive_stuff *stuffp, const struct cdrom_msf *msf)
"%02x:%02x:%02x -- %02x:%02x:%02x\n", "%02x:%02x:%02x -- %02x:%02x:%02x\n",
cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6]); cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6]);
outsb((unsigned int) stuffp->wreg_data, cmd, sizeof cmd); outsb(stuffp->wreg_data, cmd, sizeof cmd);
if (-1 == mcdx_getval(stuffp, 3 * HZ, 0, NULL)) { if (-1 == mcdx_getval(stuffp, 3 * HZ, 0, NULL)) {
xwarn("playmsf() timeout\n"); xwarn("playmsf() timeout\n");
...@@ -1910,8 +1895,8 @@ static int mcdx_requestversion(struct s_drive_stuff *stuffp, struct s_version *v ...@@ -1910,8 +1895,8 @@ static int mcdx_requestversion(struct s_drive_stuff *stuffp, struct s_version *v
static int mcdx_reset(struct s_drive_stuff *stuffp, enum resetmodes mode, int tries) static int mcdx_reset(struct s_drive_stuff *stuffp, enum resetmodes mode, int tries)
{ {
if (mode == HARD) { if (mode == HARD) {
outb(0, (unsigned int) stuffp->wreg_chn); /* no dma, no irq -> hardware */ outb(0, stuffp->wreg_chn); /* no dma, no irq -> hardware */
outb(0, (unsigned int) stuffp->wreg_reset); /* hw reset */ outb(0, stuffp->wreg_reset); /* hw reset */
return 0; return 0;
} else } else
return mcdx_talk(stuffp, "\x60", 1, NULL, 1, 5 * HZ, tries); return mcdx_talk(stuffp, "\x60", 1, NULL, 1, 5 * HZ, tries);
...@@ -1945,13 +1930,13 @@ mcdx_getval(struct s_drive_stuff *stuffp, int to, int delay, char *buf) ...@@ -1945,13 +1930,13 @@ mcdx_getval(struct s_drive_stuff *stuffp, int to, int delay, char *buf)
if (!buf) if (!buf)
buf = &c; buf = &c;
while (inb((unsigned int) stuffp->rreg_status) & MCDX_RBIT_STEN) { while (inb(stuffp->rreg_status) & MCDX_RBIT_STEN) {
if (time_after(jiffies, timeout)) if (time_after(jiffies, timeout))
return -1; return -1;
mcdx_delay(stuffp, delay); mcdx_delay(stuffp, delay);
} }
*buf = (unsigned char) inb((unsigned int) stuffp->rreg_data) & 0xff; *buf = (unsigned char) inb(stuffp->rreg_data) & 0xff;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment