Skip to contentSkip to conversation

fix casting problem in megaraid driver

PATCH In review [email protected] 3 participants 4 messages Sep 1, 2000 – Sep 6, 2000

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

PATCH 1/1 fix casting problem in megaraid driver

This patch fixes bug where mbox's pointer was cast to integer, caused segfault.

-Andrew

drivers/scsi/megaraid.c +8 -3
diff -Nur linux-2.4.0test7/drivers/scsi/megaraid.c linux-2.4.0test7.megaraid/drivers/scsi/megaraid.c
@@ -129,6 +129,11 @@
  *    occasionally hang. We check such cards and report them. You can
  *    get firmware upgrades to flash the board to 3.10 for free.
  *
+ * Version 1.08
+ *    Fixed bug where pointer of mbox was cast to integer in
+ *    mega_register_mailbox causing segfault. 
+ *    Aug 31 2000 Andrew Ip <[email protected]>   
+ *
  * BUGS:
  *     Some older 2.1 kernels (eg. 2.1.90) have a bug in pci.c that
  *     fails to detect the controller as a pci device on the system.
@@ -1282,13 +1287,13 @@
  *   10 01 numstatus byte
  *   11 01 status byte
  *--------------------------------------------------------------------*/
-static int mega_register_mailbox (mega_host_config * megaCfg, u32 paddr)
+static int mega_register_mailbox (mega_host_config * megaCfg, u64 paddr)
 {
   /* align on 16-byte boundry */
   megaCfg->mbox = &megaCfg->mailbox64.mailbox;
-  megaCfg->mbox = (mega_mailbox *) ((((u32) megaCfg->mbox) + 16) & 0xfffffff0);
+  megaCfg->mbox = (mega_mailbox *) ((((u64) megaCfg->mbox) + 16) & 0xfffffffffffffff0);
   megaCfg->mbox64 = (mega_mailbox64 *) (megaCfg->mbox - 4);
-  paddr = (paddr + 4 + 16) & 0xfffffff0;
+  paddr = (paddr + 4 + 16) & 0xfffffffffffffff0;
 
   /* Register mailbox area with the firmware */
   if (!(megaCfg->flag & BOARD_QUARTZ)) {
#1 lore raw

PATCH 1/1 fix casting problem in megaraid driver

This patch fixes bug where mbox's pointer was cast to integer, caused segfault.

-Andrew

drivers/scsi/megaraid.c +8 -3
diff -Nur linux-2.4.0test7/drivers/scsi/megaraid.c linux-2.4.0test7.megaraid/drivers/scsi/megaraid.c
@@ -129,6 +129,11 @@
  *    occasionally hang. We check such cards and report them. You can
  *    get firmware upgrades to flash the board to 3.10 for free.
  *
+ * Version 1.08
+ *    Fixed bug where pointer of mbox was cast to integer in
+ *    mega_register_mailbox causing segfault. 
+ *    Aug 31 2000 Andrew Ip <[email protected]>   
+ *
  * BUGS:
  *     Some older 2.1 kernels (eg. 2.1.90) have a bug in pci.c that
  *     fails to detect the controller as a pci device on the system.
@@ -1282,13 +1287,13 @@
  *   10 01 numstatus byte
  *   11 01 status byte
  *--------------------------------------------------------------------*/
-static int mega_register_mailbox (mega_host_config * megaCfg, u32 paddr)
+static int mega_register_mailbox (mega_host_config * megaCfg, u64 paddr)
 {
   /* align on 16-byte boundry */
   megaCfg->mbox = &megaCfg->mailbox64.mailbox;
-  megaCfg->mbox = (mega_mailbox *) ((((u32) megaCfg->mbox) + 16) & 0xfffffff0);
+  megaCfg->mbox = (mega_mailbox *) ((((u64) megaCfg->mbox) + 16) & 0xfffffffffffffff0);
   megaCfg->mbox64 = (mega_mailbox64 *) (megaCfg->mbox - 4);
-  paddr = (paddr + 4 + 16) & 0xfffffff0;
+  paddr = (paddr + 4 + 16) & 0xfffffffffffffff0;
 
   /* Register mailbox area with the firmware */
   if (!(megaCfg->flag & BOARD_QUARTZ)) {
#2 lore raw
In reply to [email protected]

Hi Andrew,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · On Tue, 5 Sep 2000 10:50:38 -0700, [email protected] said:

Andrew> This patch fixes bug where mbox's pointer was cast to Andrew> integer, caused segfault.

The patch looks a bit suspicious to me. I'm not familiar with the megaraid driver, but looking at the relevant code, it's clear that "paddr" really is a 32 bit PCI address (it gets written to the device as a sequence of four byte writes), so changing it to u64 clearly isn't 100% correct.

Now, looking at the code that calls the routine in question:

mega_register_mailbox (megaCfg, virt_to_bus ((void *) &megaCfg->mailbox64));

we find that, yuck, this is another driver that hasn't been updated for the PCI DMA interface. Not much point in hacking around in this driver until this gets rectified...

Note that the virt_to_bus() and bus_to_virt() macros have been obsoleted by the PCI DMA interface and will be removed from the kernel at some future point (I'm tempted to do this now so we'll discover right away which drivers need cleaning up).

Can you ask the megaraid maintainers to update their driver to use the PCI DMA interface?

	--david
#3 lore raw
In reply to [email protected]
Quoted 9 lines

we find that, yuck, this is another driver that hasn't been updated for the PCI DMA interface. Not much point in hacking around in this driver until this gets rectified...

Note that the virt_to_bus() and bus_to_virt() macros have been obsoleted by the PCI DMA interface and will be removed from the kernel at some future point (I'm tempted to do this now so we'll discover right away which drivers need cleaning up).

Quoted 4 lines

Can you ask the megaraid maintainers to update their driver to use the PCI DMA interface?

	--david

The update is in progress at AMI already.

Thanks,
Matt