[SCSI] mpt2sas: fix cleanup on controller resource mapping failure
authorJoe Lawrence <joe.lawrence@stratus.com>
Thu, 8 Aug 2013 20:45:38 +0000 (16:45 -0400)
committerJames Bottomley <JBottomley@Parallels.com>
Mon, 26 Aug 2013 14:53:44 +0000 (18:53 +0400)
If mpt2sas_base_map_resources takes an early error path then its
counterpart, mpt2sas_base_free_resources needs to be careful about
cleaning up:

  1 - _base_mask_interrupts and _base_make_ioc_ready require memory
      mapped I/O registers, make sure that this is true.

  2 - _base_free_irq iterates over the adapter's reply_queue_list, so
      move this list head initialization out of _base_enable_msix to
      _scsih_probe so this will always be safe.

  3 - check that the controller PCI device and its BARs have been
      enabled before disabling them.

Signed-off-by: Joe Lawrence <joe.lawrence@stratus.com>
Acked-by: Sreekanth Reddy <Sreekanth.Reddy@lsi.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
drivers/scsi/mpt2sas/mpt2sas_base.c
drivers/scsi/mpt2sas/mpt2sas_scsih.c

index ccd6d5a97ec31c17caa0b20b855c22077c4314df..cf131a3de61c3787c942ed2cac380aa904df208f 100644 (file)
@@ -1409,8 +1409,6 @@ _base_enable_msix(struct MPT2SAS_ADAPTER *ioc)
        int i;
        u8 try_msix = 0;
 
-       INIT_LIST_HEAD(&ioc->reply_queue_list);
-
        if (msix_disable == -1 || msix_disable == 0)
                try_msix = 1;
 
@@ -1489,6 +1487,7 @@ mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
        if (pci_enable_device_mem(pdev)) {
                printk(MPT2SAS_WARN_FMT "pci_enable_device_mem: "
                    "failed\n", ioc->name);
+               ioc->bars = 0;
                return -ENODEV;
        }
 
@@ -1497,6 +1496,7 @@ mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
            MPT2SAS_DRIVER_NAME)) {
                printk(MPT2SAS_WARN_FMT "pci_request_selected_regions: "
                    "failed\n", ioc->name);
+               ioc->bars = 0;
                r = -ENODEV;
                goto out_fail;
        }
@@ -4229,18 +4229,25 @@ mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc)
        dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
            __func__));
 
-       _base_mask_interrupts(ioc);
-       ioc->shost_recovery = 1;
-       _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
-       ioc->shost_recovery = 0;
+       if (ioc->chip_phys && ioc->chip) {
+               _base_mask_interrupts(ioc);
+               ioc->shost_recovery = 1;
+               _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
+               ioc->shost_recovery = 0;
+       }
+
        _base_free_irq(ioc);
        _base_disable_msix(ioc);
-       if (ioc->chip_phys)
+
+       if (ioc->chip_phys && ioc->chip)
                iounmap(ioc->chip);
        ioc->chip_phys = 0;
-       pci_release_selected_regions(ioc->pdev, ioc->bars);
-       pci_disable_pcie_error_reporting(pdev);
-       pci_disable_device(pdev);
+
+       if (pci_is_enabled(pdev)) {
+               pci_release_selected_regions(ioc->pdev, ioc->bars);
+               pci_disable_pcie_error_reporting(pdev);
+               pci_disable_device(pdev);
+       }
        return;
 }
 
index 51004768d0f57d83a479fa979cc89cd39229a077..389d79290861602ea6da7de90c57901e6cb561ec 100644 (file)
@@ -8175,6 +8175,7 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
        INIT_LIST_HEAD(&ioc->delayed_tr_list);
        INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
+       INIT_LIST_HEAD(&ioc->reply_queue_list);
 
        /* init shost parameters */
        shost->max_cmd_len = 32;