megaraid: fix mega_internal_command oops
Subsystems (2)
PATCH 16/17 megaraid: fix mega_internal_command oops
From: FUJITA Tomonori <[email protected]>
scsi_cmnd->cmnd was changed from a static array to a pointer post 2.6.25. It breaks mega_internal_command():
static intmega_internal_command(adapter_t *adapter, megacmd_t *mc, mega_passthru *pthru) {
...
scb = &adapter->int_scb; memset(scb, 0, sizeof(scb_t)); scmd = &adapter->int_scmd; memset(scmd, 0, sizeof(Scsi_Cmnd)); sdev = kzalloc(sizeof(struct scsi_device), GFP_KERNEL); scmd->device = sdev; scmd->device->host = adapter->host; scmd->host_scribble = (void *)scb; scmd->cmnd[0] = MEGA_INTERNAL_CMD;
mega_internal_command() uses scsi_cmnd allocated internally so scmd->cmnd is NULL here. This patch adds a static array for cdb to adapter_t and uses it here. This also uses scsi_allocate_command/scsi_free_command, the recommended way to allocate struct scsi_cmnd since the driver might use sense_buffer in struct scsi_cmnd.
Addresses http://bugzilla.kernel.org/show_bug.cgi?id=11792
---
drivers/scsi/megaraid.c | 11 ++++++++--- drivers/scsi/megaraid.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-)
drivers/scsi/megaraid.c renamed from drivers/scsi/megaraid.c~megaraid-fix-mega_internal_command-oops +8 -3
@@ -4402,6 +4402,10 @@ mega_internal_command(adapter_t *adapterscb_t *scb;int rval; + scmd =scsi_allocate_command (GFP_KERNEL ); +if (!scmd) +return -ENOMEM ; +/* * The internal commands share one command id and hence are * serialized. This is so because we want to reserve maximum number of
@@ -4412,12 +4416,11 @@ mega_internal_command(adapter_t *adapter scb = &adapter->int_scb;memset (scb,0 ,sizeof (scb_t)); - scmd = &adapter->int_scmd; -memset (scmd,0 ,sizeof (Scsi_Cmnd)); - sdev =kzalloc (sizeof (struct scsi_device ),GFP_KERNEL ); scmd->device = sdev; +memset (adapter->int_cdb,0 ,sizeof (adapter->int_cdb)); + scmd->cmnd = adapter->int_cdb; scmd->device->host = adapter->host; scmd->host_scribble = (void *)scb; scmd->cmnd[0 ] =MEGA_INTERNAL_CMD ;
@@ -4456,6 +4459,8 @@ mega_internal_command(adapter_t *adaptermutex_unlock (&adapter->int_mtx); +scsi_free_command (GFP_KERNEL , scmd); +return rval; }
drivers/scsi/megaraid.h renamed from drivers/scsi/megaraid.h~megaraid-fix-mega_internal_command-oops +1 -1
@@ -888,8 +888,8 @@ typedef struct {u8 sglen;/* f/w supported scatter-gather list length */ +unsigned char int_cdb[MAX_COMMAND_SIZE ];scb_t int_scb; -Scsi_Cmnd int_scmd;struct mutex int_mtx;/* To synchronize the internal commands */ struct completion int_waitq;/* wait queue for internal
_
ACK.
Bo Yang
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, October 29, 2008 5:25 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Yang, Bo; [email protected]; [email protected]
Subject: [patch 16/17] megaraid: fix mega_internal_command oops
From: FUJITA Tomonori <[email protected]>
scsi_cmnd->cmnd was changed from a static array to a pointer post 2.6.25. It breaks mega_internal_command():
static intmega_internal_command(adapter_t *adapter, megacmd_t *mc, mega_passthru *pthru) {
...
scb = &adapter->int_scb;
memset(scb, 0, sizeof(scb_t));
scmd = &adapter->int_scmd;
memset(scmd, 0, sizeof(Scsi_Cmnd));
sdev = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
scmd->device = sdev;
scmd->device->host = adapter->host;
scmd->host_scribble = (void *)scb;
scmd->cmnd[0] = MEGA_INTERNAL_CMD;mega_internal_command() uses scsi_cmnd allocated internally so scmd->cmnd is NULL here. This patch adds a static array for cdb to adapter_t and uses it here. This also uses scsi_allocate_command/scsi_free_command, the recommended way to allocate struct scsi_cmnd since the driver might use sense_buffer in struct scsi_cmnd.
Addresses http://bugzilla.kernel.org/show_bug.cgi?id=11792
---
drivers/scsi/megaraid.c | 11 ++++++++--- drivers/scsi/megaraid.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-)
drivers/scsi/megaraid.c renamed from drivers/scsi/megaraid.c~megaraid-fix-mega_internal_command-oops +8 -3
@@ -4402,6 +4402,10 @@ mega_internal_command(adapter_t *adapterscb_t *scb;int rval; + scmd =scsi_allocate_command (GFP_KERNEL ); +if (!scmd) +return -ENOMEM ; +/* * The internal commands share one command id and hence are * serialized. This is so because we want to reserve maximum number of
@@ -4412,12 +4416,11 @@ mega_internal_command(adapter_t *adapter scb = &adapter->int_scb;memset (scb,0 ,sizeof (scb_t)); - scmd = &adapter->int_scmd; -memset (scmd,0 ,sizeof (Scsi_Cmnd)); - sdev =kzalloc (sizeof (struct scsi_device ),GFP_KERNEL ); scmd->device = sdev; +memset (adapter->int_cdb,0 ,sizeof (adapter->int_cdb)); + scmd->cmnd = adapter->int_cdb; scmd->device->host = adapter->host; scmd->host_scribble = (void *)scb; scmd->cmnd[0 ] =MEGA_INTERNAL_CMD ;
@@ -4456,6 +4459,8 @@ mega_internal_command(adapter_t *adaptermutex_unlock (&adapter->int_mtx); +scsi_free_command (GFP_KERNEL , scmd); +return rval; }
drivers/scsi/megaraid.h renamed from drivers/scsi/megaraid.h~megaraid-fix-mega_internal_command-oops +1 -1
@@ -888,8 +888,8 @@ typedef struct {u8 sglen;/* f/w supported scatter-gather list length */ +unsigned char int_cdb[MAX_COMMAND_SIZE ];scb_t int_scb; -Scsi_Cmnd int_scmd;struct mutex int_mtx;/* To synchronize the internal commands */ struct completion int_waitq;/* wait queue for internal
_