diff -urpN --exclude-from=/home/davej/.exclude bk-linus/drivers/scsi/megaraid.c linux-2.5/drivers/scsi/megaraid.c --- bk-linus/drivers/scsi/megaraid.c 2002-11-21 02:18:08.000000000 +0000 +++ linux-2.5/drivers/scsi/megaraid.c 2002-11-21 18:00:46.000000000 +0000 @@ -586,10 +586,10 @@ MODULE_LICENSE ("GPL"); #define DRIVER_LOCK(p) #define DRIVER_UNLOCK(p) #define IO_LOCK_T unsigned long io_flags = 0 -#define IO_LOCK(host) spin_lock_irqsave(host->host_lock,io_flags) -#define IO_UNLOCK(host) spin_unlock_irqrestore(host->host_lock,io_flags) -#define IO_LOCK_IRQ(host) spin_lock_irq(host->host_lock) -#define IO_UNLOCK_IRQ(host) spin_unlock_irq(host->host_lock) +#define IO_LOCK(host) spin_lock_irqsave((host)->host_lock,io_flags) +#define IO_UNLOCK(host) spin_unlock_irqrestore((host)->host_lock,io_flags) +#define IO_LOCK_IRQ(host) spin_lock_irq((host)->host_lock) +#define IO_UNLOCK_IRQ(host) spin_unlock_irq((host)->host_lock) #define queue_task_irq(a,b) queue_task(a,b) #define queue_task_irq_off(a,b) queue_task(a,b) @@ -614,8 +614,8 @@ MODULE_DESCRIPTION ("LSI Logic MegaRAID #define DRIVER_LOCK(p) #define DRIVER_UNLOCK(p) #define IO_LOCK_T unsigned long io_flags = 0 -#define IO_LOCK(host) spin_lock_irqsave(host->host_lock,io_flags); -#define IO_UNLOCK(host) spin_unlock_irqrestore(host->host_lock,io_flags); +#define IO_LOCK(host) spin_lock_irqsave(&io_request_lock,io_flags); +#define IO_UNLOCK(host) spin_unlock_irqrestore(&io_request_lock,io_flags); #define pci_free_consistent(a,b,c,d) #define pci_unmap_single(a,b,c,d) @@ -1151,12 +1151,12 @@ static void mega_cmd_done (mega_host_con if (mbox->cmd == MEGA_MBOXCMD_PASSTHRU) { memcpy (SCpnt->sense_buffer, pthru->reqsensearea, 14); } else if (mbox->cmd == MEGA_MBOXCMD_EXTPASSTHRU) { - SCpnt->result = (DRIVER_SENSE << 24) | (DID_OK << 16) | (CHECK_CONDITION < 1); + SCpnt->result = (DRIVER_SENSE << 24) | (DID_OK << 16) | (CHECK_CONDITION << 1); memcpy( SCpnt->sense_buffer, epthru->reqsensearea, 14 ); - SCpnt->result = (DRIVER_SENSE << 24) | (DID_OK << 16) | (CHECK_CONDITION < 1); + SCpnt->result = (DRIVER_SENSE << 24) | (DID_OK << 16) | (CHECK_CONDITION << 1); /*SCpnt->result = (DRIVER_SENSE << 24) | (DID_ERROR << 16) | status;*/ @@ -1864,7 +1864,14 @@ static mega_scb *mega_ioctl (mega_host_c return NULL; } - copy_from_user (pScb->buff_ptr, user_area, xfer_size); + if (copy_from_user (pScb->buff_ptr, user_area, xfer_size)) { + printk + ("megaraid: Copy failed for M_RD_IOCTL_CMD_NEW.\n"); + SCpnt->result = (DID_ERROR << 16); + callDone (SCpnt); + kfree (pScb->buff_ptr); + return NULL; + } pScb->iDataSize = xfer_size; switch (data[0]) { @@ -2273,7 +2280,7 @@ static int megaIssueCmd (mega_host_confi u_char byte; -#ifdef __LP64__ +#if BITS_PER_LONG==64 u64 phys_mbox; #else u32 phys_mbox; @@ -2559,7 +2566,7 @@ mega_register_mailbox (mega_host_config megaCfg->mbox = &megaCfg->mailbox64.mailbox; #endif -#ifdef __LP64__ +#if BITS_PER_LONG==64 megaCfg->mbox = (mega_mailbox *) ((((u64) megaCfg->mbox) + 16) & ((u64) (-1) ^ 0x0F)); megaCfg->adjdmahandle64 = (megaCfg->dma_handle64 + 16) & ((u64) (-1) ^ 0x0F); megaCfg->mbox64 = (mega_mailbox64 *) ((u_char *) megaCfg->mbox - sizeof (u64)); @@ -2837,7 +2844,7 @@ static int mega_findCard (Scsi_Host_Temp int i; -#ifdef __LP64__ +#if BITS_PER_LONG==64 u64 megaBase; #else u32 megaBase; @@ -3074,10 +3081,12 @@ static int mega_findCard (Scsi_Host_Temp /* * which firmware */ - if( strcmp(megaCfg->fwVer, "H01.07") == 0 || - strcmp(megaCfg->fwVer, "H01.08") == 0 ) { + if( strcmp(megaCfg->fwVer, "H01.07") == 0 || + strcmp(megaCfg->fwVer, "H01.08") == 0 || + strcmp(megaCfg->fwVer, "H01.09") == 0 ) + { printk(KERN_WARNING - "megaraid: Firmware H.01.07 or H.01.08 on 1M/2M " + "megaraid: Firmware H.01.07/8/9 on 1M/2M " "controllers\nmegaraid: do not support 64 bit " "addressing.\n" "megaraid: DISABLING 64 bit support.\n"); @@ -3149,7 +3158,7 @@ static int mega_findCard (Scsi_Host_Temp /* Set the Mode of addressing to 64 bit */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) if ((megaCfg->flag & BOARD_64BIT) && BITS_PER_LONG == 64) -#ifdef __LP64__ +#if BITS_PER_LONG==64 pdev->dma_mask = 0xffffffffffffffff; #else pdev->dma_mask = 0xffffffff; @@ -4444,10 +4453,10 @@ static int megadev_ioctl (struct inode * /* * Copy struct mcontroller to user area */ - copy_to_user (ioc.data, - mcontroller + adapno, - sizeof (struct mcontroller)); - return 0; + return copy_to_user (ioc.data, + mcontroller + adapno, + sizeof (struct mcontroller)) + ? -EFAULT : 0; default: return (-EINVAL); @@ -4541,7 +4550,16 @@ static int megadev_ioctl (struct inode * if (inlen) { /* copyin the user data */ - copy_from_user(kvaddr, (char *)uaddr, length ); + if (copy_from_user(kvaddr, (char *)uaddr, length )) { + printk(KERN_WARNING "megaraid:copy failed\n"); + dma_free_consistent(pdevp, length, kvaddr, dma_addr); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) /*0x20400 */ + kfree(scsicmd); +#else + scsi_init_free((char *)scsicmd, sizeof(Scsi_Cmnd)); +#endif + return -EFAULT; + } } } @@ -4558,7 +4576,17 @@ static int megadev_ioctl (struct inode * down(&mimd_ioctl_sem); if( !scsicmd->result && outlen ) { - copy_to_user(uaddr, kvaddr, length); + if (copy_to_user(uaddr, kvaddr, length)) { + up(&mimd_ioctl_sem); + dma_free_consistent(pdevp, length, kvaddr, dma_addr); + printk(KERN_WARNING "megaraid:copy failed\n"); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) /*0x20400 */ + kfree(scsicmd); +#else + scsi_init_free((char *)scsicmd, sizeof(Scsi_Cmnd)); +#endif + return -EFAULT; + } } /* @@ -4682,9 +4710,19 @@ static int megadev_ioctl (struct inode * if (inlen) { if (ioc.mbox[0] == MEGA_MBOXCMD_PASSTHRU) { /* copyin the user data */ - copy_from_user (kvaddr, uaddr, ioc.pthru.dataxferlen); + ret = copy_from_user (kvaddr, uaddr, ioc.pthru.dataxferlen); } else { - copy_from_user (kvaddr, uaddr, inlen); + ret = copy_from_user (kvaddr, uaddr, inlen); + } + if (ret) { + dma_free_consistent(pdevp, PAGE_SIZE, kvaddr, dma_addr ); + printk (KERN_WARNING "megaraid:copy failed\n"); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) /*0x20400 */ + kfree(scsicmd); +#else + scsi_init_free((char *)scsicmd, sizeof(Scsi_Cmnd)); +#endif + return -EFAULT; } } } @@ -4702,10 +4740,22 @@ static int megadev_ioctl (struct inode * if (!scsicmd->result && outlen) { if (ioc.mbox[0] == MEGA_MBOXCMD_PASSTHRU) { - copy_to_user (uaddr, kvaddr, ioc.pthru.dataxferlen); + ret = copy_to_user (uaddr, kvaddr, ioc.pthru.dataxferlen); } else { - copy_to_user (uaddr, kvaddr, outlen); + ret = copy_to_user (uaddr, kvaddr, outlen); } + if (ret) { + up (&mimd_ioctl_sem); + dma_free_consistent(pdevp, PAGE_SIZE, kvaddr, dma_addr ); + printk (KERN_WARNING "megaraid:copy failed\n"); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) /*0x20400 */ + kfree(scsicmd); +#else + scsi_init_free((char *)scsicmd, sizeof(Scsi_Cmnd)); +#endif + return -EFAULT; + } + } /* diff -urpN --exclude-from=/home/davej/.exclude bk-linus/drivers/scsi/megaraid.h linux-2.5/drivers/scsi/megaraid.h --- bk-linus/drivers/scsi/megaraid.h 2002-11-21 02:18:08.000000000 +0000 +++ linux-2.5/drivers/scsi/megaraid.h 2002-11-21 18:00:46.000000000 +0000 @@ -707,7 +707,7 @@ typedef struct _mega_host_config { u8 numldrv; u32 flag; -#ifdef __LP64__ +#if BITS_PER_LONG==64 u64 base; #else u32 base;