[PATCH] CCISS: use ARRAY_SIZE without intermediates
[safe/jmp/linux-2.6] / drivers / block / cciss.c
index e2df9eb..94e82a2 100644 (file)
@@ -104,8 +104,6 @@ static const struct pci_device_id cciss_pci_device_id[] = {
 };
 MODULE_DEVICE_TABLE(pci, cciss_pci_device_id);
 
-#define NR_PRODUCTS ARRAY_SIZE(products)
-
 /*  board_id = Subsystem Device ID & Vendor ID
  *  product = Marketing Name for the board
  *  access = Address of the struct of function pointers 
@@ -2638,16 +2636,6 @@ static void print_cfg_table( CfgTable_struct *tb)
 }
 #endif /* CCISS_DEBUG */ 
 
-static void release_io_mem(ctlr_info_t *c)
-{
-       /* if IO mem was not protected do nothing */
-       if( c->io_mem_addr == 0)
-               return;
-       release_region(c->io_mem_addr, c->io_mem_length);
-       c->io_mem_addr = 0;
-       c->io_mem_length = 0;
-}
-
 static int find_PCI_BAR_index(struct pci_dev *pdev,
                                unsigned long pci_bar_addr)
 {
@@ -2744,7 +2732,7 @@ static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
        __u64 cfg_offset;
        __u32 cfg_base_addr;
        __u64 cfg_base_addr_index;
-       int i;
+       int i, err;
 
        /* check to see if controller has been disabled */
        /* BEFORE trying to enable it */
@@ -2752,13 +2740,21 @@ static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
        if(!(command & 0x02))
        {
                printk(KERN_WARNING "cciss: controller appears to be disabled\n");
-               return(-1);
+               return -ENODEV;
        }
 
-       if (pci_enable_device(pdev))
+       err = pci_enable_device(pdev);
+       if (err)
        {
                printk(KERN_ERR "cciss: Unable to Enable PCI device\n");
-               return( -1);
+               return err;
+       }
+
+       err = pci_request_regions(pdev, "cciss");
+       if (err) {
+               printk(KERN_ERR "cciss: Cannot obtain PCI resources, "
+                       "aborting\n");
+               goto err_out_disable_pdev;
        }
 
        subsystem_vendor_id = pdev->subsystem_vendor;
@@ -2766,31 +2762,6 @@ static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
        board_id = (((__u32) (subsystem_device_id << 16) & 0xffff0000) |
                                        subsystem_vendor_id);
 
-       /* search for our IO range so we can protect it */
-       for(i=0; i<DEVICE_COUNT_RESOURCE; i++)
-       {
-               /* is this an IO range */ 
-               if( pci_resource_flags(pdev, i) & 0x01 ) {
-                       c->io_mem_addr = pci_resource_start(pdev, i);
-                       c->io_mem_length = pci_resource_end(pdev, i) -
-                               pci_resource_start(pdev, i) +1;
-#ifdef CCISS_DEBUG
-                       printk("IO value found base_addr[%d] %lx %lx\n", i,
-                               c->io_mem_addr, c->io_mem_length);
-#endif /* CCISS_DEBUG */
-                       /* register the IO range */ 
-                       if(!request_region( c->io_mem_addr,
-                                        c->io_mem_length, "cciss"))
-                       {
-                               printk(KERN_WARNING "cciss I/O memory range already in use addr=%lx length=%ld\n",
-                               c->io_mem_addr, c->io_mem_length);
-                               c->io_mem_addr= 0;
-                               c->io_mem_length = 0;
-                       } 
-                       break;
-               }
-       }
-
 #ifdef CCISS_DEBUG
        printk("command = %x\n", command);
        printk("irq = %x\n", pdev->irq);
@@ -2824,7 +2795,8 @@ static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
        }
        if (scratchpad != CCISS_FIRMWARE_READY) {
                printk(KERN_WARNING "cciss: Board not ready.  Timed out.\n");
-               return -1;
+               err = -ENODEV;
+               goto err_out_free_res;
        }
 
        /* get the address index number */
@@ -2840,8 +2812,8 @@ static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
 #endif /* CCISS_DEBUG */
        if (cfg_base_addr_index == -1) {
                printk(KERN_WARNING "cciss: Cannot find cfg_base_addr_index\n");
-               release_io_mem(c);
-               return -1;
+               err = -ENODEV;
+               goto err_out_free_res;
        }
 
        cfg_offset = readl(c->vaddr + SA5_CTMEM_OFFSET);
@@ -2857,18 +2829,19 @@ static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
        print_cfg_table(c->cfgtable);
 #endif /* CCISS_DEBUG */
 
-       for(i=0; i<NR_PRODUCTS; i++) {
+       for(i=0; i<ARRAY_SIZE(products); i++) {
                if (board_id == products[i].board_id) {
                        c->product_name = products[i].product_name;
                        c->access = *(products[i].access);
                        break;
                }
        }
-       if (i == NR_PRODUCTS) {
+       if (i == ARRAY_SIZE(products)) {
                printk(KERN_WARNING "cciss: Sorry, I don't know how"
                        " to access the Smart Array controller %08lx\n", 
                                (unsigned long)board_id);
-               return -1;
+               err = -ENODEV;
+               goto err_out_free_res;
        }
        if (  (readb(&c->cfgtable->Signature[0]) != 'C') ||
              (readb(&c->cfgtable->Signature[1]) != 'I') ||
@@ -2876,7 +2849,8 @@ static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
              (readb(&c->cfgtable->Signature[3]) != 'S') )
        {
                printk("Does not appear to be a valid CISS config table\n");
-               return -1;
+               err = -ENODEV;
+               goto err_out_free_res;
        }
 
 #ifdef CONFIG_X86
@@ -2920,10 +2894,17 @@ static int cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
        {
                printk(KERN_WARNING "cciss: unable to get board into"
                                        " simple mode\n");
-               return -1;
+               err = -ENODEV;
+               goto err_out_free_res;
        }
        return 0;
 
+err_out_free_res:
+       pci_release_regions(pdev);
+
+err_out_disable_pdev:
+       pci_disable_device(pdev);
+       return err;
 }
 
 /* 
@@ -3103,11 +3084,8 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
        int i;
        int j;
        int rc;
+       int dac;
 
-       printk(KERN_DEBUG "cciss: Device 0x%x has been found at"
-                       " bus %d dev %d func %d\n",
-               pdev->device, pdev->bus->number, PCI_SLOT(pdev->devfn),
-                       PCI_FUNC(pdev->devfn));
        i = alloc_cciss_hba();
        if(i < 0)
                return (-1);
@@ -3123,11 +3101,11 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
 
        /* configure PCI DMA stuff */
        if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK))
-               printk("cciss: using DAC cycles\n");
+               dac = 1;
        else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK))
-               printk("cciss: not using DAC cycles\n");
+               dac = 0;
        else {
-               printk("cciss: no suitable DMA available\n");
+               printk(KERN_ERR "cciss: no suitable DMA available\n");
                goto clean1;
        }
 
@@ -3158,6 +3136,11 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
                        hba[i]->intr[SIMPLE_MODE_INT], hba[i]->devname);
                goto clean2;
        }
+
+       printk(KERN_INFO "%s: <0x%x> at PCI %s IRQ %d%s using DAC\n",
+               hba[i]->devname, pdev->device, pci_name(pdev),
+               hba[i]->intr[SIMPLE_MODE_INT], dac ? "" : " not");
+
        hba[i]->cmd_pool_bits = kmalloc(((NR_CMDS+BITS_PER_LONG-1)/BITS_PER_LONG)*sizeof(unsigned long), GFP_KERNEL);
        hba[i]->cmd_pool = (CommandList_struct *)pci_alloc_consistent(
                hba[i]->pdev, NR_CMDS * sizeof(CommandList_struct), 
@@ -3267,7 +3250,6 @@ clean4:
 clean2:
        unregister_blkdev(hba[i]->major, hba[i]->devname);
 clean1:
-       release_io_mem(hba[i]);
        hba[i]->busy_initializing = 0;
        free_hba(i);
        return(-1);
@@ -3313,7 +3295,6 @@ static void __devexit cciss_remove_one (struct pci_dev *pdev)
                 pci_disable_msi(hba[i]->pdev);
 #endif /* CONFIG_PCI_MSI */
 
-       pci_set_drvdata(pdev, NULL);
        iounmap(hba[i]->vaddr);
        cciss_unregister_scsi(i);  /* unhook from SCSI subsystem */
        unregister_blkdev(hba[i]->major, hba[i]->devname);
@@ -3340,7 +3321,9 @@ static void __devexit cciss_remove_one (struct pci_dev *pdev)
 #ifdef CONFIG_CISS_SCSI_TAPE
        kfree(hba[i]->scsi_rejects.complete);
 #endif
-       release_io_mem(hba[i]);
+       pci_release_regions(pdev);
+       pci_disable_device(pdev);
+       pci_set_drvdata(pdev, NULL);
        free_hba(i);
 }