Commit 058a26b7 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by Linus Torvalds

[PATCH] cyc2x: sanitize ioremap usage & more

	I wrote this driver a long time ago, and now, playing with my
brand new PARISC machine I found these problems, could you please apply
this patch?

	Ah, the "& more" refers to some alignment problems also solved
in this patch.
parent 566fa176
...@@ -70,12 +70,12 @@ MODULE_LICENSE("GPL"); ...@@ -70,12 +70,12 @@ MODULE_LICENSE("GPL");
static int load_cyc2x(struct cycx_hw *hw, struct cycx_firmware *cfm, u32 len); static int load_cyc2x(struct cycx_hw *hw, struct cycx_firmware *cfm, u32 len);
static void cycx_bootcfg(struct cycx_hw *hw); static void cycx_bootcfg(struct cycx_hw *hw);
static int reset_cyc2x(u32 addr); static int reset_cyc2x(void *addr);
static int detect_cyc2x(u32 addr); static int detect_cyc2x(void *addr);
/* Miscellaneous functions */ /* Miscellaneous functions */
static void delay_cycx(int sec); static void delay_cycx(int sec);
static int get_option_index(u32 *optlist, u32 optval); static int get_option_index(long *optlist, long optval);
static u16 checksum(u8 *buf, u32 len); static u16 checksum(u8 *buf, u32 len);
#define wait_cyc(addr) cycx_exec(addr + CMD_OFFSET) #define wait_cyc(addr) cycx_exec(addr + CMD_OFFSET)
...@@ -92,14 +92,14 @@ static char copyright[] = "(c) 1998-2003 Arnaldo Carvalho de Melo " ...@@ -92,14 +92,14 @@ static char copyright[] = "(c) 1998-2003 Arnaldo Carvalho de Melo "
* These are arrays of configuration options used by verification routines. * These are arrays of configuration options used by verification routines.
* The first element of each array is its size (i.e. number of options). * The first element of each array is its size (i.e. number of options).
*/ */
static u32 cyc2x_dpmbase_options[] = { static long cyc2x_dpmbase_options[] = {
20, 20,
0xA0000, 0xA4000, 0xA8000, 0xAC000, 0xB0000, 0xB4000, 0xB8000, 0xA0000, 0xA4000, 0xA8000, 0xAC000, 0xB0000, 0xB4000, 0xB8000,
0xBC000, 0xC0000, 0xC4000, 0xC8000, 0xCC000, 0xD0000, 0xD4000, 0xBC000, 0xC0000, 0xC4000, 0xC8000, 0xCC000, 0xD0000, 0xD4000,
0xD8000, 0xDC000, 0xE0000, 0xE4000, 0xE8000, 0xEC000 0xD8000, 0xDC000, 0xE0000, 0xE4000, 0xE8000, 0xEC000
}; };
static u32 cycx_2x_irq_options[] = { 7, 3, 5, 9, 10, 11, 12, 15 }; static long cycx_2x_irq_options[] = { 7, 3, 5, 9, 10, 11, 12, 15 };
/* Kernel Loadable Module Entry Points */ /* Kernel Loadable Module Entry Points */
/* Module 'insert' entry point. /* Module 'insert' entry point.
...@@ -137,7 +137,7 @@ void cycx_drv_cleanup(void) ...@@ -137,7 +137,7 @@ void cycx_drv_cleanup(void)
EXPORT_SYMBOL(cycx_setup); EXPORT_SYMBOL(cycx_setup);
int cycx_setup(struct cycx_hw *hw, void *cfm, u32 len) int cycx_setup(struct cycx_hw *hw, void *cfm, u32 len)
{ {
unsigned long dpmbase = hw->dpmbase; long dpmbase = (long)hw->dpmbase;
int err; int err;
/* Verify IRQ configuration options */ /* Verify IRQ configuration options */
...@@ -147,17 +147,17 @@ int cycx_setup(struct cycx_hw *hw, void *cfm, u32 len) ...@@ -147,17 +147,17 @@ int cycx_setup(struct cycx_hw *hw, void *cfm, u32 len)
} }
/* Setup adapter dual-port memory window and test memory */ /* Setup adapter dual-port memory window and test memory */
if (!hw->dpmbase) { if (!dpmbase) {
printk(KERN_ERR "%s: you must specify the dpm address!\n", printk(KERN_ERR "%s: you must specify the dpm address!\n",
modname); modname);
return -EINVAL; return -EINVAL;
} else if (!get_option_index(cyc2x_dpmbase_options, hw->dpmbase)) { } else if (!get_option_index(cyc2x_dpmbase_options, dpmbase)) {
printk(KERN_ERR "%s: memory address 0x%lX is invalid!\n", printk(KERN_ERR "%s: memory address 0x%lX is invalid!\n",
modname, dpmbase); modname, dpmbase);
return -EINVAL; return -EINVAL;
} }
hw->dpmbase = (u32)ioremap(dpmbase, CYCX_WINDOWSIZE); hw->dpmbase = ioremap(dpmbase, CYCX_WINDOWSIZE);
hw->dpmsize = CYCX_WINDOWSIZE; hw->dpmsize = CYCX_WINDOWSIZE;
if (!detect_cyc2x(hw->dpmbase)) { if (!detect_cyc2x(hw->dpmbase)) {
...@@ -181,8 +181,7 @@ int cycx_setup(struct cycx_hw *hw, void *cfm, u32 len) ...@@ -181,8 +181,7 @@ int cycx_setup(struct cycx_hw *hw, void *cfm, u32 len)
EXPORT_SYMBOL(cycx_down); EXPORT_SYMBOL(cycx_down);
int cycx_down(struct cycx_hw *hw) int cycx_down(struct cycx_hw *hw)
{ {
iounmap((u32 *)hw->dpmbase); iounmap(hw->dpmbase);
return 0; return 0;
} }
...@@ -204,7 +203,7 @@ void cycx_intr(struct cycx_hw *hw) ...@@ -204,7 +203,7 @@ void cycx_intr(struct cycx_hw *hw)
* o Set exec flag. * o Set exec flag.
* o Busy-wait until flag is reset. */ * o Busy-wait until flag is reset. */
EXPORT_SYMBOL(cycx_exec); EXPORT_SYMBOL(cycx_exec);
int cycx_exec(u32 addr) int cycx_exec(void *addr)
{ {
u16 i = 0; u16 i = 0;
/* wait till addr content is zeroed */ /* wait till addr content is zeroed */
...@@ -250,7 +249,7 @@ int cycx_poke(struct cycx_hw *hw, u32 addr, void *buf, u32 len) ...@@ -250,7 +249,7 @@ int cycx_poke(struct cycx_hw *hw, u32 addr, void *buf, u32 len)
/* Load Aux Routines */ /* Load Aux Routines */
/* Reset board hardware. /* Reset board hardware.
return 1 if memory exists at addr and 0 if not. */ return 1 if memory exists at addr and 0 if not. */
static int memory_exists(u32 addr) static int memory_exists(void *addr)
{ {
int tries = 0; int tries = 0;
...@@ -268,9 +267,9 @@ static int memory_exists(u32 addr) ...@@ -268,9 +267,9 @@ static int memory_exists(u32 addr)
} }
/* Load reset code. */ /* Load reset code. */
static void reset_load(u32 addr, u8 *buffer, u32 cnt) static void reset_load(void *addr, u8 *buffer, u32 cnt)
{ {
u32 pt_code = addr + RESET_OFFSET; void *pt_code = addr + RESET_OFFSET;
u16 i; /*, j; */ u16 i; /*, j; */
for (i = 0 ; i < cnt ; i++) { for (i = 0 ; i < cnt ; i++) {
...@@ -282,7 +281,7 @@ static void reset_load(u32 addr, u8 *buffer, u32 cnt) ...@@ -282,7 +281,7 @@ static void reset_load(u32 addr, u8 *buffer, u32 cnt)
/* Load buffer using boot interface. /* Load buffer using boot interface.
* o copy data from buffer to Cyclom-X memory * o copy data from buffer to Cyclom-X memory
* o wait for reset code to copy it to right portion of memory */ * o wait for reset code to copy it to right portion of memory */
static int buffer_load(u32 addr, u8 *buffer, u32 cnt) static int buffer_load(void *addr, u8 *buffer, u32 cnt)
{ {
memcpy_toio(addr + DATA_OFFSET, buffer, cnt); memcpy_toio(addr + DATA_OFFSET, buffer, cnt);
writew(GEN_BOOT_DAT, addr + CMD_OFFSET); writew(GEN_BOOT_DAT, addr + CMD_OFFSET);
...@@ -291,7 +290,7 @@ static int buffer_load(u32 addr, u8 *buffer, u32 cnt) ...@@ -291,7 +290,7 @@ static int buffer_load(u32 addr, u8 *buffer, u32 cnt)
} }
/* Set up entry point and kick start Cyclom-X CPU. */ /* Set up entry point and kick start Cyclom-X CPU. */
static void cycx_start(u32 addr) static void cycx_start(void *addr)
{ {
/* put in 0x30 offset the jump instruction to the code entry point */ /* put in 0x30 offset the jump instruction to the code entry point */
writeb(0xea, addr + 0x30); writeb(0xea, addr + 0x30);
...@@ -305,9 +304,9 @@ static void cycx_start(u32 addr) ...@@ -305,9 +304,9 @@ static void cycx_start(u32 addr)
} }
/* Load and boot reset code. */ /* Load and boot reset code. */
static void cycx_reset_boot(u32 addr, u8 *code, u32 len) static void cycx_reset_boot(void *addr, u8 *code, u32 len)
{ {
u32 pt_start = addr + START_OFFSET; void *pt_start = addr + START_OFFSET;
writeb(0xea, pt_start++); /* jmp to f000:3f00 */ writeb(0xea, pt_start++); /* jmp to f000:3f00 */
writeb(0x00, pt_start++); writeb(0x00, pt_start++);
...@@ -322,9 +321,9 @@ static void cycx_reset_boot(u32 addr, u8 *code, u32 len) ...@@ -322,9 +321,9 @@ static void cycx_reset_boot(u32 addr, u8 *code, u32 len)
} }
/* Load data.bin file through boot (reset) interface. */ /* Load data.bin file through boot (reset) interface. */
static int cycx_data_boot(u32 addr, u8 *code, u32 len) static int cycx_data_boot(void *addr, u8 *code, u32 len)
{ {
u32 pt_boot_cmd = addr + CMD_OFFSET; void *pt_boot_cmd = addr + CMD_OFFSET;
u32 i; u32 i;
/* boot buffer lenght */ /* boot buffer lenght */
...@@ -353,9 +352,9 @@ static int cycx_data_boot(u32 addr, u8 *code, u32 len) ...@@ -353,9 +352,9 @@ static int cycx_data_boot(u32 addr, u8 *code, u32 len)
/* Load code.bin file through boot (reset) interface. */ /* Load code.bin file through boot (reset) interface. */
static int cycx_code_boot(u32 addr, u8 *code, u32 len) static int cycx_code_boot(void *addr, u8 *code, u32 len)
{ {
u32 pt_boot_cmd = addr + CMD_OFFSET; void *pt_boot_cmd = addr + CMD_OFFSET;
u32 i; u32 i;
/* boot buffer lenght */ /* boot buffer lenght */
...@@ -392,7 +391,7 @@ static int load_cyc2x(struct cycx_hw *hw, struct cycx_firmware *cfm, u32 len) ...@@ -392,7 +391,7 @@ static int load_cyc2x(struct cycx_hw *hw, struct cycx_firmware *cfm, u32 len)
u8 *reset_image, u8 *reset_image,
*data_image, *data_image,
*code_image; *code_image;
u32 pt_cycld = hw->dpmbase + 0x400; void *pt_cycld = hw->dpmbase + 0x400;
u16 cksum; u16 cksum;
/* Announce */ /* Announce */
...@@ -426,7 +425,7 @@ static int load_cyc2x(struct cycx_hw *hw, struct cycx_firmware *cfm, u32 len) ...@@ -426,7 +425,7 @@ static int load_cyc2x(struct cycx_hw *hw, struct cycx_firmware *cfm, u32 len)
if (cksum != cfm->checksum) { if (cksum != cfm->checksum) {
printk(KERN_ERR "%s:%s: firmware corrupted!\n", printk(KERN_ERR "%s:%s: firmware corrupted!\n",
modname, __FUNCTION__); modname, __FUNCTION__);
printk(KERN_ERR " cdsize = 0x%x (expected 0x%lx)\n", printk(KERN_ERR " cdsize = 0x%lx (expected 0x%lx)\n",
len - sizeof(struct cycx_firmware) - 1, len - sizeof(struct cycx_firmware) - 1,
cfm->info.codesize); cfm->info.codesize);
printk(KERN_ERR " chksum = 0x%x (expected 0x%x)\n", printk(KERN_ERR " chksum = 0x%x (expected 0x%x)\n",
...@@ -435,9 +434,7 @@ static int load_cyc2x(struct cycx_hw *hw, struct cycx_firmware *cfm, u32 len) ...@@ -435,9 +434,7 @@ static int load_cyc2x(struct cycx_hw *hw, struct cycx_firmware *cfm, u32 len)
} }
/* If everything is ok, set reset, data and code pointers */ /* If everything is ok, set reset, data and code pointers */
img_hdr = (struct cycx_fw_header *)&cfm->image;
img_hdr = (struct cycx_fw_header *)(((u8 *)cfm) +
sizeof(struct cycx_firmware) - 1);
#ifdef FIRMWARE_DEBUG #ifdef FIRMWARE_DEBUG
printk(KERN_INFO "%s:%s: image sizes\n", __FUNCTION__, modname); printk(KERN_INFO "%s:%s: image sizes\n", __FUNCTION__, modname);
printk(KERN_INFO " reset=%lu\n", img_hdr->reset_size); printk(KERN_INFO " reset=%lu\n", img_hdr->reset_size);
...@@ -526,7 +523,7 @@ static void cycx_bootcfg(struct cycx_hw *hw) ...@@ -526,7 +523,7 @@ static void cycx_bootcfg(struct cycx_hw *hw)
* Return 1 if detected o.k. or 0 if failed. * Return 1 if detected o.k. or 0 if failed.
* Note: This test is destructive! Adapter will be left in shutdown * Note: This test is destructive! Adapter will be left in shutdown
* state after the test. */ * state after the test. */
static int detect_cyc2x(u32 addr) static int detect_cyc2x(void *addr)
{ {
reset_cyc2x(addr); reset_cyc2x(addr);
...@@ -536,7 +533,7 @@ static int detect_cyc2x(u32 addr) ...@@ -536,7 +533,7 @@ static int detect_cyc2x(u32 addr)
/* Miscellaneous */ /* Miscellaneous */
/* Get option's index into the options list. /* Get option's index into the options list.
* Return option's index (1 .. N) or zero if option is invalid. */ * Return option's index (1 .. N) or zero if option is invalid. */
static int get_option_index(u32 *optlist, u32 optval) static int get_option_index(long *optlist, long optval)
{ {
int i = 1; int i = 1;
...@@ -548,7 +545,7 @@ static int get_option_index(u32 *optlist, u32 optval) ...@@ -548,7 +545,7 @@ static int get_option_index(u32 *optlist, u32 optval)
} }
/* Reset adapter's CPU. */ /* Reset adapter's CPU. */
static int reset_cyc2x(u32 addr) static int reset_cyc2x(void *addr)
{ {
writeb(0, addr + RST_ENABLE); writeb(0, addr + RST_ENABLE);
delay_cycx(2); delay_cycx(2);
......
...@@ -223,7 +223,7 @@ static int cycx_wan_setup(struct wan_device *wandev, wandev_conf_t *conf) ...@@ -223,7 +223,7 @@ static int cycx_wan_setup(struct wan_device *wandev, wandev_conf_t *conf)
/* Configure hardware, load firmware, etc. */ /* Configure hardware, load firmware, etc. */
memset(&card->hw, 0, sizeof(card->hw)); memset(&card->hw, 0, sizeof(card->hw));
card->hw.irq = irq; card->hw.irq = irq;
card->hw.dpmbase = conf->maddr; card->hw.dpmbase = (void *)conf->maddr;
card->hw.dpmsize = CYCX_WINDOWSIZE; card->hw.dpmsize = CYCX_WINDOWSIZE;
card->hw.fwid = CFID_X25_2X; card->hw.fwid = CFID_X25_2X;
card->lock = SPIN_LOCK_UNLOCKED; card->lock = SPIN_LOCK_UNLOCKED;
...@@ -236,7 +236,7 @@ static int cycx_wan_setup(struct wan_device *wandev, wandev_conf_t *conf) ...@@ -236,7 +236,7 @@ static int cycx_wan_setup(struct wan_device *wandev, wandev_conf_t *conf)
/* Initialize WAN device data space */ /* Initialize WAN device data space */
wandev->irq = irq; wandev->irq = irq;
wandev->dma = wandev->ioport = 0; wandev->dma = wandev->ioport = 0;
wandev->maddr = card->hw.dpmbase; wandev->maddr = (unsigned long)card->hw.dpmbase;
wandev->msize = card->hw.dpmsize; wandev->msize = card->hw.dpmsize;
wandev->hw_opt[2] = 0; wandev->hw_opt[2] = 0;
wandev->hw_opt[3] = card->hw.fwid; wandev->hw_opt[3] = card->hw.fwid;
......
...@@ -52,7 +52,7 @@ struct cycx_device { ...@@ -52,7 +52,7 @@ struct cycx_device {
char in_isr; /* interrupt-in-service flag */ char in_isr; /* interrupt-in-service flag */
char buff_int_mode_unbusy; /* flag for carrying out dev_tint */ char buff_int_mode_unbusy; /* flag for carrying out dev_tint */
wait_queue_head_t wait_stats; /* to wait for the STATS indication */ wait_queue_head_t wait_stats; /* to wait for the STATS indication */
u32 mbox; /* -> mailbox */ void *mbox; /* -> mailbox */
void (*isr)(struct cycx_device* card); /* interrupt service routine */ void (*isr)(struct cycx_device* card); /* interrupt service routine */
int (*exec)(struct cycx_device* card, void* u_cmd, void* u_data); int (*exec)(struct cycx_device* card, void* u_cmd, void* u_data);
union { union {
......
...@@ -90,7 +90,7 @@ struct cycx_firmware { ...@@ -90,7 +90,7 @@ struct cycx_firmware {
unsigned short reserved[6]; unsigned short reserved[6];
char descr[CFM_DESCR_LEN]; char descr[CFM_DESCR_LEN];
struct cycx_fw_info info; struct cycx_fw_info info;
unsigned char image[1]; unsigned char image[0];
}; };
struct cycx_fw_header { struct cycx_fw_header {
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
struct cycx_hw { struct cycx_hw {
u32 fwid; u32 fwid;
int irq; int irq;
u32 dpmbase; void *dpmbase;
u32 dpmsize; u32 dpmsize;
u32 reserved[5]; u32 reserved[5];
}; };
...@@ -58,7 +58,7 @@ extern int cycx_setup(struct cycx_hw *hw, void *sfm, u32 len); ...@@ -58,7 +58,7 @@ extern int cycx_setup(struct cycx_hw *hw, void *sfm, u32 len);
extern int cycx_down(struct cycx_hw *hw); extern int cycx_down(struct cycx_hw *hw);
extern int cycx_peek(struct cycx_hw *hw, u32 addr, void *buf, u32 len); extern int cycx_peek(struct cycx_hw *hw, u32 addr, void *buf, u32 len);
extern int cycx_poke(struct cycx_hw *hw, u32 addr, void *buf, u32 len); extern int cycx_poke(struct cycx_hw *hw, u32 addr, void *buf, u32 len);
extern int cycx_exec(u32 addr); extern int cycx_exec(void *addr);
extern void cycx_inten(struct cycx_hw *hw); extern void cycx_inten(struct cycx_hw *hw);
extern void cycx_intr(struct cycx_hw *hw); extern void cycx_intr(struct cycx_hw *hw);
......
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