[PATCH] : Megaraid patch for 2.6 3/5

From: Paul Wagland
Date: Thu Feb 19 2004 - 21:12:57 EST


Hi all,

LSI have released a new driver for the 2.4 series of kernels, but the
2.6 driver is still based on a much older version of this driver. This
is the beginnings of my efforts to update the 2.6 driver so that it is
up to date. This patch removes the local copying of the pdev structure,
this has two advantages, a) the error handling is simpler, since we
don't need to clean up memory anymore, and b) the code is smaller, this
change saves about 500 bytes in the module size.

patch is attached and below.

diff --recursive --ignore-all-space --unified linux-2.6.2.o/drivers/scsi/megaraid.c linux-2.6.2.megaraid/drivers/scsi/megaraid.c
--- linux-2.6.2.o/drivers/scsi/megaraid.c 2004-02-20 01:32:26.000000000 +0100
+++ linux-2.6.2.megaraid/drivers/scsi/megaraid.c 2004-02-20 01:32:30.000000000 +0100
@@ -2338,13 +2338,9 @@
struct pci_dev *pdev;
int len = 0;

- if( make_local_pdev(adapter, &pdev) != 0 ) {
- *eof = 1;
- return len;
- }
+ pdev = adapter->dev;

if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
- free_local_pdev(pdev);
*eof = 1;
return len;
}
@@ -2357,8 +2353,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
*eof = 1;

return len;
@@ -2377,8 +2371,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
*eof = 1;

return len;
@@ -2408,13 +2400,9 @@
char str[256];
int len = 0;

- if( make_local_pdev(adapter, &pdev) != 0 ) {
- *eof = 1;
- return len;
- }
+ pdev = adapter->dev;

if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
- free_local_pdev(pdev);
*eof = 1;
return len;
}
@@ -2427,8 +2415,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
*eof = 1;

return len;
@@ -2476,8 +2462,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
*eof = 1;

return len;
@@ -2599,12 +2583,9 @@
char str[80];
int i;

- if( make_local_pdev(adapter, &pdev) != 0 ) {
- return len;
- }
+ pdev = adapter->dev;

if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
- free_local_pdev(pdev);
return len;
}

@@ -2616,8 +2597,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
return len;
}

@@ -2629,8 +2608,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
return len;
}

@@ -2713,8 +2690,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
return len;
}

@@ -2883,12 +2858,9 @@
int len = 0;
int i;

- if( make_local_pdev(adapter, &pdev) != 0 ) {
- return len;
- }
+ pdev = adapter->dev;

if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
- free_local_pdev(pdev);
return len;
}

@@ -2900,8 +2872,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
return len;
}

@@ -2932,8 +2902,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
return len;
}

@@ -2952,8 +2920,6 @@
pci_free_consistent(pdev, array_sz, disk_array,
disk_array_dma_handle);

- free_local_pdev(pdev);
-
return len;
}

@@ -2977,8 +2943,6 @@
disk_array,
disk_array_dma_handle);

- free_local_pdev(pdev);
-
return len;
}
}
@@ -3103,8 +3067,6 @@
pci_free_consistent(pdev, array_sz, disk_array,
disk_array_dma_handle);

- free_local_pdev(pdev);
-
return len;
}

@@ -3478,8 +3440,7 @@
* For all internal commands, the buffer must be allocated in
* <4GB address range
*/
- if( make_local_pdev(adapter, &pdev) != 0 )
- return -EIO;
+ pdev = adapter->dev;

/* Is it a passthru command or a DCMD */
if( uioc.uioc_rmbox[0] == MEGA_MBOXCMD_PASSTHRU ) {
@@ -3490,7 +3451,6 @@
&pthru_dma_hndl);

if( pthru == NULL ) {
- free_local_pdev(pdev);
return (-ENOMEM);
}

@@ -3509,8 +3469,6 @@
sizeof(mega_passthru), pthru,
pthru_dma_hndl);

- free_local_pdev(pdev);
-
return (-EFAULT);
}

@@ -3528,8 +3486,6 @@
pthru,
pthru_dma_hndl);

- free_local_pdev(pdev);
-
return (-ENOMEM);
}

@@ -3598,8 +3554,6 @@
pci_free_consistent(pdev, sizeof(mega_passthru),
pthru, pthru_dma_hndl);

- free_local_pdev(pdev);
-
return rval;
}
else {
@@ -3613,7 +3567,6 @@
uioc.xferlen, &data_dma_hndl);

if( data == NULL ) {
- free_local_pdev(pdev);
return (-ENOMEM);
}

@@ -3634,8 +3587,6 @@
uioc.xferlen,
data, data_dma_hndl);

- free_local_pdev(pdev);
-
return (-EFAULT);
}
}
@@ -3658,8 +3609,6 @@
data_dma_hndl);
}

- free_local_pdev(pdev);
-
return rval;
}

@@ -3680,8 +3629,6 @@
data_dma_hndl);
}

- free_local_pdev(pdev);
-
return rval;
}

@@ -4413,13 +4360,12 @@
* For all internal commands, the buffer must be allocated in <4GB
* address range
*/
- if( make_local_pdev(adapter, &pdev) != 0 ) return -1;
+ pdev = adapter->dev;

pthru = pci_alloc_consistent(pdev, sizeof(mega_passthru),
&pthru_dma_handle);

if( pthru == NULL ) {
- free_local_pdev(pdev);
return -1;
}

@@ -4455,8 +4401,6 @@
pci_free_consistent(pdev, sizeof(mega_passthru), pthru,
pthru_dma_handle);

- free_local_pdev(pdev);
-
return rval;
}

@@ -4590,29 +4534,6 @@
}


-static inline int
-make_local_pdev(adapter_t *adapter, struct pci_dev **pdev)
-{
- *pdev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL);
-
- if( *pdev == NULL ) return -1;
-
- memcpy(*pdev, adapter->dev, sizeof(struct pci_dev));
-
- if( pci_set_dma_mask(*pdev, 0xffffffff) != 0 ) {
- kfree(*pdev);
- return -1;
- }
-
- return 0;
-}
-
-static inline void
-free_local_pdev(struct pci_dev *pdev)
-{
- kfree(pdev);
-}
-
static struct scsi_host_template megaraid_template = {
.module = THIS_MODULE,
.name = "MegaRAID",
diff --recursive --ignore-all-space --unified linux-2.6.2.o/drivers/scsi/megaraid.h linux-2.6.2.megaraid/drivers/scsi/megaraid.h
--- linux-2.6.2.o/drivers/scsi/megaraid.h 2004-02-20 00:40:05.000000000 +0100
+++ linux-2.6.2.megaraid/drivers/scsi/megaraid.h 2004-02-20 01:32:30.000000000 +0100
@@ -1055,8 +1055,6 @@
static int mega_internal_dev_inquiry(adapter_t *, u8, u8, dma_addr_t);
static inline caddr_t mega_allocate_inquiry(dma_addr_t *, struct pci_dev *);
static inline void mega_free_inquiry(caddr_t, dma_addr_t, struct pci_dev *);
-static inline int make_local_pdev(adapter_t *, struct pci_dev **);
-static inline void free_local_pdev(struct pci_dev *);

static int mega_support_ext_cdb(adapter_t *);
static mega_passthru* mega_prepare_passthru(adapter_t *, scb_t *,

diff --recursive --ignore-all-space --unified linux-2.6.2.o/drivers/scsi/megaraid.c linux-2.6.2.megaraid/drivers/scsi/megaraid.c
--- linux-2.6.2.o/drivers/scsi/megaraid.c 2004-02-20 01:32:26.000000000 +0100
+++ linux-2.6.2.megaraid/drivers/scsi/megaraid.c 2004-02-20 01:32:30.000000000 +0100
@@ -2338,13 +2338,9 @@
struct pci_dev *pdev;
int len = 0;

- if( make_local_pdev(adapter, &pdev) != 0 ) {
- *eof = 1;
- return len;
- }
+ pdev = adapter->dev;

if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
- free_local_pdev(pdev);
*eof = 1;
return len;
}
@@ -2357,8 +2353,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
*eof = 1;

return len;
@@ -2377,8 +2371,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
*eof = 1;

return len;
@@ -2408,13 +2400,9 @@
char str[256];
int len = 0;

- if( make_local_pdev(adapter, &pdev) != 0 ) {
- *eof = 1;
- return len;
- }
+ pdev = adapter->dev;

if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
- free_local_pdev(pdev);
*eof = 1;
return len;
}
@@ -2427,8 +2415,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
*eof = 1;

return len;
@@ -2476,8 +2462,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
*eof = 1;

return len;
@@ -2599,12 +2583,9 @@
char str[80];
int i;

- if( make_local_pdev(adapter, &pdev) != 0 ) {
- return len;
- }
+ pdev = adapter->dev;

if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
- free_local_pdev(pdev);
return len;
}

@@ -2616,8 +2597,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
return len;
}

@@ -2629,8 +2608,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
return len;
}

@@ -2713,8 +2690,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
return len;
}

@@ -2883,12 +2858,9 @@
int len = 0;
int i;

- if( make_local_pdev(adapter, &pdev) != 0 ) {
- return len;
- }
+ pdev = adapter->dev;

if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
- free_local_pdev(pdev);
return len;
}

@@ -2900,8 +2872,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
return len;
}

@@ -2932,8 +2902,6 @@

mega_free_inquiry(inquiry, dma_handle, pdev);

- free_local_pdev(pdev);
-
return len;
}

@@ -2952,8 +2920,6 @@
pci_free_consistent(pdev, array_sz, disk_array,
disk_array_dma_handle);

- free_local_pdev(pdev);
-
return len;
}

@@ -2977,8 +2943,6 @@
disk_array,
disk_array_dma_handle);

- free_local_pdev(pdev);
-
return len;
}
}
@@ -3103,8 +3067,6 @@
pci_free_consistent(pdev, array_sz, disk_array,
disk_array_dma_handle);

- free_local_pdev(pdev);
-
return len;
}

@@ -3478,8 +3440,7 @@
* For all internal commands, the buffer must be allocated in
* <4GB address range
*/
- if( make_local_pdev(adapter, &pdev) != 0 )
- return -EIO;
+ pdev = adapter->dev;

/* Is it a passthru command or a DCMD */
if( uioc.uioc_rmbox[0] == MEGA_MBOXCMD_PASSTHRU ) {
@@ -3490,7 +3451,6 @@
&pthru_dma_hndl);

if( pthru == NULL ) {
- free_local_pdev(pdev);
return (-ENOMEM);
}

@@ -3509,8 +3469,6 @@
sizeof(mega_passthru), pthru,
pthru_dma_hndl);

- free_local_pdev(pdev);
-
return (-EFAULT);
}

@@ -3528,8 +3486,6 @@
pthru,
pthru_dma_hndl);

- free_local_pdev(pdev);
-
return (-ENOMEM);
}

@@ -3598,8 +3554,6 @@
pci_free_consistent(pdev, sizeof(mega_passthru),
pthru, pthru_dma_hndl);

- free_local_pdev(pdev);
-
return rval;
}
else {
@@ -3613,7 +3567,6 @@
uioc.xferlen, &data_dma_hndl);

if( data == NULL ) {
- free_local_pdev(pdev);
return (-ENOMEM);
}

@@ -3634,8 +3587,6 @@
uioc.xferlen,
data, data_dma_hndl);

- free_local_pdev(pdev);
-
return (-EFAULT);
}
}
@@ -3658,8 +3609,6 @@
data_dma_hndl);
}

- free_local_pdev(pdev);
-
return rval;
}

@@ -3680,8 +3629,6 @@
data_dma_hndl);
}

- free_local_pdev(pdev);
-
return rval;
}

@@ -4413,13 +4360,12 @@
* For all internal commands, the buffer must be allocated in <4GB
* address range
*/
- if( make_local_pdev(adapter, &pdev) != 0 ) return -1;
+ pdev = adapter->dev;

pthru = pci_alloc_consistent(pdev, sizeof(mega_passthru),
&pthru_dma_handle);

if( pthru == NULL ) {
- free_local_pdev(pdev);
return -1;
}

@@ -4455,8 +4401,6 @@
pci_free_consistent(pdev, sizeof(mega_passthru), pthru,
pthru_dma_handle);

- free_local_pdev(pdev);
-
return rval;
}

@@ -4590,29 +4534,6 @@
}


-static inline int
-make_local_pdev(adapter_t *adapter, struct pci_dev **pdev)
-{
- *pdev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL);
-
- if( *pdev == NULL ) return -1;
-
- memcpy(*pdev, adapter->dev, sizeof(struct pci_dev));
-
- if( pci_set_dma_mask(*pdev, 0xffffffff) != 0 ) {
- kfree(*pdev);
- return -1;
- }
-
- return 0;
-}
-
-static inline void
-free_local_pdev(struct pci_dev *pdev)
-{
- kfree(pdev);
-}
-
static struct scsi_host_template megaraid_template = {
.module = THIS_MODULE,
.name = "MegaRAID",
diff --recursive --ignore-all-space --unified linux-2.6.2.o/drivers/scsi/megaraid.h linux-2.6.2.megaraid/drivers/scsi/megaraid.h
--- linux-2.6.2.o/drivers/scsi/megaraid.h 2004-02-20 00:40:05.000000000 +0100
+++ linux-2.6.2.megaraid/drivers/scsi/megaraid.h 2004-02-20 01:32:30.000000000 +0100
@@ -1055,8 +1055,6 @@
static int mega_internal_dev_inquiry(adapter_t *, u8, u8, dma_addr_t);
static inline caddr_t mega_allocate_inquiry(dma_addr_t *, struct pci_dev *);
static inline void mega_free_inquiry(caddr_t, dma_addr_t, struct pci_dev *);
-static inline int make_local_pdev(adapter_t *, struct pci_dev **);
-static inline void free_local_pdev(struct pci_dev *);

static int mega_support_ext_cdb(adapter_t *);
static mega_passthru* mega_prepare_passthru(adapter_t *, scb_t *,

Attachment: signature.asc
Description: This is a digitally signed message part