]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bnxt_en: fix pci cleanup in bnxt_init_one() failure path
authorSathya Perla <sathya.perla@broadcom.com>
Tue, 21 Feb 2017 00:25:18 +0000 (19:25 -0500)
committerChuck Anderson <chuck.anderson@oracle.com>
Mon, 6 Mar 2017 21:35:42 +0000 (13:35 -0800)
Orabug: 25645429

In the bnxt_init_one() failure path, bar1 and bar2 are not
being unmapped.  This commit fixes this issue.  Reorganize the
code so that bnxt_init_one()'s failure path and bnxt_remove_one()
can call the same function to do the PCI cleanup.

Signed-off-by: Michael Chan <michael.chan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 17086399c113d933e1202697f85b8f0f82fcb8ce)
Signed-off-by: Brian Maly <brian.maly@oracle.com>
Conflicts:
drivers/net/ethernet/broadcom/bnxt/bnxt.c

drivers/net/ethernet/broadcom/bnxt/bnxt.c

index f5b65fcac21500044aee74c2559d216c54dcddae..59fe1a19a7eddcd9176c8417859d236107168e4e 100644 (file)
@@ -6672,6 +6672,31 @@ int bnxt_reserve_rings(struct bnxt *bp, int tx, int rx, int tcs, int tx_xdp)
        return 0;
 }
 
+static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev)
+{
+       if (bp->bar2) {
+               pci_iounmap(pdev, bp->bar2);
+               bp->bar2 = NULL;
+       }
+
+       if (bp->bar1) {
+               pci_iounmap(pdev, bp->bar1);
+               bp->bar1 = NULL;
+       }
+
+       if (bp->bar0) {
+               pci_iounmap(pdev, bp->bar0);
+               bp->bar0 = NULL;
+       }
+}
+
+static void bnxt_cleanup_pci(struct bnxt *bp)
+{
+       bnxt_unmap_bars(bp, bp->pdev);
+       pci_release_regions(bp->pdev);
+       pci_disable_device(bp->pdev);
+}
+
 static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
 {
        int rc;
@@ -6759,25 +6784,10 @@ static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
        bp->current_interval = BNXT_TIMER_INTERVAL;
 
        clear_bit(BNXT_STATE_OPEN, &bp->state);
-
        return 0;
 
 init_err_release:
-       if (bp->bar2) {
-               pci_iounmap(pdev, bp->bar2);
-               bp->bar2 = NULL;
-       }
-
-       if (bp->bar1) {
-               pci_iounmap(pdev, bp->bar1);
-               bp->bar1 = NULL;
-       }
-
-       if (bp->bar0) {
-               pci_iounmap(pdev, bp->bar0);
-               bp->bar0 = NULL;
-       }
-
+       bnxt_unmap_bars(bp, pdev);
        pci_release_regions(pdev);
 
 init_err_disable:
@@ -7228,15 +7238,10 @@ static void bnxt_remove_one(struct pci_dev *pdev)
        bnxt_hwrm_func_drv_unrgtr(bp);
        bnxt_free_hwrm_resources(bp);
        bnxt_dcb_free(bp);
-       pci_iounmap(pdev, bp->bar2);
-       pci_iounmap(pdev, bp->bar1);
-       pci_iounmap(pdev, bp->bar0);
        kfree(bp->edev);
        bp->edev = NULL;
+       bnxt_cleanup_pci(bp);
        free_netdev(dev);
-
-       pci_release_regions(pdev);
-       pci_disable_device(pdev);
 }
 
 static int bnxt_probe_phy(struct bnxt *bp)
@@ -7468,17 +7473,16 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        dev->netdev_ops = &bnxt_netdev_ops;
        dev->watchdog_timeo = BNXT_TX_TIMEOUT;
        dev->ethtool_ops = &bnxt_ethtool_ops;
-
        pci_set_drvdata(pdev, dev);
 
        rc = bnxt_alloc_hwrm_resources(bp);
        if (rc)
-               goto init_err;
+               goto init_err_pci_clean;
 
        mutex_init(&bp->hwrm_cmd_lock);
        rc = bnxt_hwrm_ver_get(bp);
        if (rc)
-               goto init_err;
+               goto init_err_pci_clean;
 
        bnxt_hwrm_fw_set_time(bp);
 
@@ -7514,11 +7518,11 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
        rc = bnxt_hwrm_func_drv_rgtr(bp);
        if (rc)
-               goto init_err;
+               goto init_err_pci_clean;
 
        rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0);
        if (rc)
-               goto init_err;
+               goto init_err_pci_clean;
 
        bp->ulp_probe = bnxt_ulp_probe;
 
@@ -7528,7 +7532,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                netdev_err(bp->dev, "hwrm query capability failure rc: %x\n",
                           rc);
                rc = -1;
-               goto init_err;
+               goto init_err_pci_clean;
        }
 
        rc = bnxt_hwrm_queue_qportcfg(bp);
@@ -7536,7 +7540,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n",
                           rc);
                rc = -1;
-               goto init_err;
+               goto init_err_pci_clean;
        }
 
        bnxt_hwrm_func_qcfg(bp);
@@ -7550,7 +7554,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (rc) {
                netdev_err(bp->dev, "Not enough rings available.\n");
                rc = -ENOMEM;
-               goto init_err;
+               goto init_err_pci_clean;
        }
 
        /* Default RSS hash cfg. */
@@ -7580,15 +7584,15 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
        rc = bnxt_probe_phy(bp);
        if (rc)
-               goto init_err;
+               goto init_err_pci_clean;
 
        rc = bnxt_hwrm_func_reset(bp);
        if (rc)
-               goto init_err;
+               goto init_err_pci_clean;
 
        rc = bnxt_init_int_mode(bp);
        if (rc)
-               goto init_err;
+               goto init_err_pci_clean;
 
        rc = register_netdev(dev);
        if (rc)
@@ -7605,10 +7609,8 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 init_err_clr_int:
        bnxt_clear_int_mode(bp);
 
-init_err:
-       pci_iounmap(pdev, bp->bar0);
-       pci_release_regions(pdev);
-       pci_disable_device(pdev);
+init_err_pci_clean:
+       bnxt_cleanup_pci(bp);
 
 init_err_free:
        free_netdev(dev);