stmmac: pci: use managed resources
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Wed, 5 Nov 2014 10:27:28 +0000 (12:27 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 6 Nov 2014 19:38:57 +0000 (14:38 -0500)
Migrate pci driver to managed resources to reduce boilerplate error handling
code.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c

index f19ac8e..5357a3f 100644 (file)
@@ -71,46 +71,37 @@ static void stmmac_default_data(void)
 static int stmmac_pci_probe(struct pci_dev *pdev,
                            const struct pci_device_id *id)
 {
-       int ret = 0;
-       void __iomem *addr = NULL;
-       struct stmmac_priv *priv = NULL;
+       struct stmmac_priv *priv;
        int i;
+       int ret;
 
        /* Enable pci device */
-       ret = pci_enable_device(pdev);
+       ret = pcim_enable_device(pdev);
        if (ret) {
                pr_err("%s : ERROR: failed to enable %s device\n", __func__,
                       pci_name(pdev));
                return ret;
        }
-       if (pci_request_regions(pdev, STMMAC_RESOURCE_NAME)) {
-               pr_err("%s: ERROR: failed to get PCI region\n", __func__);
-               ret = -ENODEV;
-               goto err_out_req_reg_failed;
-       }
 
        /* Get the base address of device */
        for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
                if (pci_resource_len(pdev, i) == 0)
                        continue;
-               addr = pci_iomap(pdev, i, 0);
-               if (addr == NULL) {
-                       pr_err("%s: ERROR: cannot map register memory aborting",
-                              __func__);
-                       ret = -EIO;
-                       goto err_out_map_failed;
-               }
+               ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
+               if (ret)
+                       return ret;
                break;
        }
+
        pci_set_master(pdev);
 
        stmmac_default_data();
 
-       priv = stmmac_dvr_probe(&(pdev->dev), &plat_dat, addr);
+       priv = stmmac_dvr_probe(&pdev->dev, &plat_dat,
+                               pcim_iomap_table(pdev)[i]);
        if (IS_ERR(priv)) {
                pr_err("%s: main driver probe failed", __func__);
-               ret = PTR_ERR(priv);
-               goto err_out;
+               return PTR_ERR(priv);
        }
        priv->dev->irq = pdev->irq;
        priv->wol_irq = pdev->irq;
@@ -120,15 +111,6 @@ static int stmmac_pci_probe(struct pci_dev *pdev,
        pr_debug("STMMAC platform driver registration completed");
 
        return 0;
-
-err_out:
-       pci_clear_master(pdev);
-err_out_map_failed:
-       pci_release_regions(pdev);
-err_out_req_reg_failed:
-       pci_disable_device(pdev);
-
-       return ret;
 }
 
 /**
@@ -141,13 +123,8 @@ err_out_req_reg_failed:
 static void stmmac_pci_remove(struct pci_dev *pdev)
 {
        struct net_device *ndev = pci_get_drvdata(pdev);
-       struct stmmac_priv *priv = netdev_priv(ndev);
 
        stmmac_dvr_remove(ndev);
-
-       pci_iounmap(pdev, priv->ioaddr);
-       pci_release_regions(pdev);
-       pci_disable_device(pdev);
 }
 
 #ifdef CONFIG_PM_SLEEP