3w-9xxx: use PCI resource length correctly
PATCH 1/1 3w-9xxx: use PCI resource length correctly
Trying to ioremap() a larger area than pci_resource_len() may fail (e.g. under Xen). Fixes 3w-9xxx to use pci_resource_len() as length parameter to ioremap() instead of PAGE_SIZE.
--- drivers/scsi/3w-9xxx.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-)
drivers/scsi/3w-9xxx.c +9 -5
@@ -1999,7 +1999,8 @@ static int __devinit twa_probe(struct pci_dev *pdev, const struct pci_device_id {struct Scsi_Host *host =NULL ;TW_Device_Extension *tw_dev; -u32 mem_addr; +int bar; +unsigned long mem_addr, mem_len;int retval = -ENODEV ; retval =pci_enable_device (pdev);
@@ -2046,12 +2047,15 @@ static int __devinit twa_probe(struct pci_dev *pdev, const struct pci_device_id }if (pdev->device ==PCI_DEVICE_ID_3WARE_9000 ) - mem_addr =pci_resource_start (pdev,1 ); + bar =1 ;else - mem_addr =pci_resource_start (pdev,2 ); + bar =2 ; + + mem_addr =pci_resource_start (pdev, bar); + mem_len =pci_resource_len (pdev, bar);/* Save base address */ - tw_dev->base_addr =ioremap (mem_addr,PAGE_SIZE ); + tw_dev->base_addr =ioremap (mem_addr, mem_len);if (!tw_dev->base_addr) {TW_PRINTK (tw_dev->host,TW_DRIVER ,0x35 ,"Failed to ioremap" ); goto out_release_mem_region;
@@ -2086,7 +2090,7 @@ static int __devinit twa_probe(struct pci_dev *pdev, const struct pci_device_idpci_set_drvdata (pdev, host); -printk (KERN_WARNING "3w-9xxx: scsi%d: Found a 3ware 9000 Storage Controller at 0x%x, IRQ: %d.\n" , +printk (KERN_WARNING "3w-9xxx: scsi%d: Found a 3ware 9000 Storage Controller at 0x%lx, IRQ: %d.\n" , host->host_no, mem_addr, pdev->irq); printk(KERN_WARNING "3w-9xxx: scsi%d: Firmware %s, BIOS %s, Ports: %d.\n", host->host_no,
Signature · 1 line
1.5.3.rc1.gaf83
Quoted 29 lines · Eduardo Habkost
Trying to
ioremap()a larger area thanpci_resource_len()may fail (e.g. under Xen). Fixes 3w-9xxx to usepci_resource_len()as length parameter toioremap()instead ofPAGE_SIZE.Signed-off-by Eduardo Habkost <[email protected]>--- drivers/scsi/3w-9xxx.c | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-)drivers/scsi/3w-9xxx.c +3
-2@@ -1999,7 +1999,8 @@ static int __devinit twa_probe(struct pci_dev *pdev, const struct pci_device_id {struct Scsi_Host *host =NULL ;TW_Device_Extension *tw_dev; -u32 mem_addr; +int bar; +unsigned long mem_addr, mem_len;int retval = -ENODEV ; retval =pci_enable_device (pdev);@@ -2046,12 +2047,15 @@ static int __devinit twa_probe(struct pci_dev *pdev, const struct pci_device_id }if (pdev->device ==PCI_DEVICE_ID_3WARE_9000 ) - mem_addr =pci_resource_start (pdev,1 ); + bar =1 ;
drivers/scsi/3w-9xxx.c static int __devinit twa_probe(struct pci_dev *pdev, const struct pci_device_id · line 2058
Quoted 10 lines
drivers/scsi/3w-9xxx.c +5
-2else - mem_addr =pci_resource_start (pdev,2 ); + bar =2 ; + + mem_addr =pci_resource_start (pdev, bar); + mem_len =pci_resource_len (pdev, bar);/* Save base address */ - tw_dev->base_addr =ioremap (mem_addr,PAGE_SIZE ); + tw_dev->base_addr =ioremap (mem_addr, mem_len);
Have you verified that the hardware resource is always a reasonable size?
Jeff
Quoted 6 lines · Jeff Garzik
drivers/scsi/3w-9xxx.c static int __devinit twa_probe(struct pci_dev *pdev, const struct pci_device_id · line 2058
Quoted 4 lines
/* Save base address */drivers/scsi/3w-9xxx.c +1
-1- tw_dev->base_addr =ioremap (mem_addr,PAGE_SIZE ); + tw_dev->base_addr =ioremap (mem_addr, mem_len);Have you verified that the hardware resource is always a reasonable size?
I have seen it on only one machine, where it was 256 bytes.
Were there cases of hardware with broken resource information, before? I didn't expect this to happen.
If it happens, wouldn't it break pci_request_regions(), anyway?
Signature · 1 line
Eduardo