diff options
author | Sathya Perla <sathya.perla@broadcom.com> | 2017-02-20 19:25:18 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-02-20 21:59:15 -0500 |
commit | 17086399c113d933e1202697f85b8f0f82fcb8ce (patch) | |
tree | 60ec6dda407753d540aa5e28b407e7e449f14a8c | |
parent | daf1f1e7841138cb0e48d52c8573a5f064d8f495 (diff) |
bnxt_en: fix pci cleanup in bnxt_init_one() failure path
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>
-rw-r--r-- | drivers/net/ethernet/broadcom/bnxt/bnxt.c | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 37b9f65f682d..6dacdf1e4d26 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c | |||
@@ -6676,6 +6676,31 @@ int bnxt_reserve_rings(struct bnxt *bp, int tx, int rx, int tcs, int tx_xdp) | |||
6676 | return 0; | 6676 | return 0; |
6677 | } | 6677 | } |
6678 | 6678 | ||
6679 | static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev) | ||
6680 | { | ||
6681 | if (bp->bar2) { | ||
6682 | pci_iounmap(pdev, bp->bar2); | ||
6683 | bp->bar2 = NULL; | ||
6684 | } | ||
6685 | |||
6686 | if (bp->bar1) { | ||
6687 | pci_iounmap(pdev, bp->bar1); | ||
6688 | bp->bar1 = NULL; | ||
6689 | } | ||
6690 | |||
6691 | if (bp->bar0) { | ||
6692 | pci_iounmap(pdev, bp->bar0); | ||
6693 | bp->bar0 = NULL; | ||
6694 | } | ||
6695 | } | ||
6696 | |||
6697 | static void bnxt_cleanup_pci(struct bnxt *bp) | ||
6698 | { | ||
6699 | bnxt_unmap_bars(bp, bp->pdev); | ||
6700 | pci_release_regions(bp->pdev); | ||
6701 | pci_disable_device(bp->pdev); | ||
6702 | } | ||
6703 | |||
6679 | static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev) | 6704 | static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev) |
6680 | { | 6705 | { |
6681 | int rc; | 6706 | int rc; |
@@ -6763,25 +6788,10 @@ static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev) | |||
6763 | bp->current_interval = BNXT_TIMER_INTERVAL; | 6788 | bp->current_interval = BNXT_TIMER_INTERVAL; |
6764 | 6789 | ||
6765 | clear_bit(BNXT_STATE_OPEN, &bp->state); | 6790 | clear_bit(BNXT_STATE_OPEN, &bp->state); |
6766 | |||
6767 | return 0; | 6791 | return 0; |
6768 | 6792 | ||
6769 | init_err_release: | 6793 | init_err_release: |
6770 | if (bp->bar2) { | 6794 | bnxt_unmap_bars(bp, pdev); |
6771 | pci_iounmap(pdev, bp->bar2); | ||
6772 | bp->bar2 = NULL; | ||
6773 | } | ||
6774 | |||
6775 | if (bp->bar1) { | ||
6776 | pci_iounmap(pdev, bp->bar1); | ||
6777 | bp->bar1 = NULL; | ||
6778 | } | ||
6779 | |||
6780 | if (bp->bar0) { | ||
6781 | pci_iounmap(pdev, bp->bar0); | ||
6782 | bp->bar0 = NULL; | ||
6783 | } | ||
6784 | |||
6785 | pci_release_regions(pdev); | 6795 | pci_release_regions(pdev); |
6786 | 6796 | ||
6787 | init_err_disable: | 6797 | init_err_disable: |
@@ -7186,17 +7196,12 @@ static void bnxt_remove_one(struct pci_dev *pdev) | |||
7186 | bnxt_hwrm_func_drv_unrgtr(bp); | 7196 | bnxt_hwrm_func_drv_unrgtr(bp); |
7187 | bnxt_free_hwrm_resources(bp); | 7197 | bnxt_free_hwrm_resources(bp); |
7188 | bnxt_dcb_free(bp); | 7198 | bnxt_dcb_free(bp); |
7189 | pci_iounmap(pdev, bp->bar2); | ||
7190 | pci_iounmap(pdev, bp->bar1); | ||
7191 | pci_iounmap(pdev, bp->bar0); | ||
7192 | kfree(bp->edev); | 7199 | kfree(bp->edev); |
7193 | bp->edev = NULL; | 7200 | bp->edev = NULL; |
7194 | if (bp->xdp_prog) | 7201 | if (bp->xdp_prog) |
7195 | bpf_prog_put(bp->xdp_prog); | 7202 | bpf_prog_put(bp->xdp_prog); |
7203 | bnxt_cleanup_pci(bp); | ||
7196 | free_netdev(dev); | 7204 | free_netdev(dev); |
7197 | |||
7198 | pci_release_regions(pdev); | ||
7199 | pci_disable_device(pdev); | ||
7200 | } | 7205 | } |
7201 | 7206 | ||
7202 | static int bnxt_probe_phy(struct bnxt *bp) | 7207 | static int bnxt_probe_phy(struct bnxt *bp) |
@@ -7428,17 +7433,16 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
7428 | dev->netdev_ops = &bnxt_netdev_ops; | 7433 | dev->netdev_ops = &bnxt_netdev_ops; |
7429 | dev->watchdog_timeo = BNXT_TX_TIMEOUT; | 7434 | dev->watchdog_timeo = BNXT_TX_TIMEOUT; |
7430 | dev->ethtool_ops = &bnxt_ethtool_ops; | 7435 | dev->ethtool_ops = &bnxt_ethtool_ops; |
7431 | |||
7432 | pci_set_drvdata(pdev, dev); | 7436 | pci_set_drvdata(pdev, dev); |
7433 | 7437 | ||
7434 | rc = bnxt_alloc_hwrm_resources(bp); | 7438 | rc = bnxt_alloc_hwrm_resources(bp); |
7435 | if (rc) | 7439 | if (rc) |
7436 | goto init_err; | 7440 | goto init_err_pci_clean; |
7437 | 7441 | ||
7438 | mutex_init(&bp->hwrm_cmd_lock); | 7442 | mutex_init(&bp->hwrm_cmd_lock); |
7439 | rc = bnxt_hwrm_ver_get(bp); | 7443 | rc = bnxt_hwrm_ver_get(bp); |
7440 | if (rc) | 7444 | if (rc) |
7441 | goto init_err; | 7445 | goto init_err_pci_clean; |
7442 | 7446 | ||
7443 | bnxt_hwrm_fw_set_time(bp); | 7447 | bnxt_hwrm_fw_set_time(bp); |
7444 | 7448 | ||
@@ -7482,11 +7486,11 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
7482 | 7486 | ||
7483 | rc = bnxt_hwrm_func_drv_rgtr(bp); | 7487 | rc = bnxt_hwrm_func_drv_rgtr(bp); |
7484 | if (rc) | 7488 | if (rc) |
7485 | goto init_err; | 7489 | goto init_err_pci_clean; |
7486 | 7490 | ||
7487 | rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0); | 7491 | rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0); |
7488 | if (rc) | 7492 | if (rc) |
7489 | goto init_err; | 7493 | goto init_err_pci_clean; |
7490 | 7494 | ||
7491 | bp->ulp_probe = bnxt_ulp_probe; | 7495 | bp->ulp_probe = bnxt_ulp_probe; |
7492 | 7496 | ||
@@ -7496,7 +7500,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
7496 | netdev_err(bp->dev, "hwrm query capability failure rc: %x\n", | 7500 | netdev_err(bp->dev, "hwrm query capability failure rc: %x\n", |
7497 | rc); | 7501 | rc); |
7498 | rc = -1; | 7502 | rc = -1; |
7499 | goto init_err; | 7503 | goto init_err_pci_clean; |
7500 | } | 7504 | } |
7501 | 7505 | ||
7502 | rc = bnxt_hwrm_queue_qportcfg(bp); | 7506 | rc = bnxt_hwrm_queue_qportcfg(bp); |
@@ -7504,7 +7508,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
7504 | netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n", | 7508 | netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n", |
7505 | rc); | 7509 | rc); |
7506 | rc = -1; | 7510 | rc = -1; |
7507 | goto init_err; | 7511 | goto init_err_pci_clean; |
7508 | } | 7512 | } |
7509 | 7513 | ||
7510 | bnxt_hwrm_func_qcfg(bp); | 7514 | bnxt_hwrm_func_qcfg(bp); |
@@ -7518,7 +7522,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
7518 | if (rc) { | 7522 | if (rc) { |
7519 | netdev_err(bp->dev, "Not enough rings available.\n"); | 7523 | netdev_err(bp->dev, "Not enough rings available.\n"); |
7520 | rc = -ENOMEM; | 7524 | rc = -ENOMEM; |
7521 | goto init_err; | 7525 | goto init_err_pci_clean; |
7522 | } | 7526 | } |
7523 | 7527 | ||
7524 | /* Default RSS hash cfg. */ | 7528 | /* Default RSS hash cfg. */ |
@@ -7548,15 +7552,15 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
7548 | 7552 | ||
7549 | rc = bnxt_probe_phy(bp); | 7553 | rc = bnxt_probe_phy(bp); |
7550 | if (rc) | 7554 | if (rc) |
7551 | goto init_err; | 7555 | goto init_err_pci_clean; |
7552 | 7556 | ||
7553 | rc = bnxt_hwrm_func_reset(bp); | 7557 | rc = bnxt_hwrm_func_reset(bp); |
7554 | if (rc) | 7558 | if (rc) |
7555 | goto init_err; | 7559 | goto init_err_pci_clean; |
7556 | 7560 | ||
7557 | rc = bnxt_init_int_mode(bp); | 7561 | rc = bnxt_init_int_mode(bp); |
7558 | if (rc) | 7562 | if (rc) |
7559 | goto init_err; | 7563 | goto init_err_pci_clean; |
7560 | 7564 | ||
7561 | rc = register_netdev(dev); | 7565 | rc = register_netdev(dev); |
7562 | if (rc) | 7566 | if (rc) |
@@ -7573,10 +7577,8 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
7573 | init_err_clr_int: | 7577 | init_err_clr_int: |
7574 | bnxt_clear_int_mode(bp); | 7578 | bnxt_clear_int_mode(bp); |
7575 | 7579 | ||
7576 | init_err: | 7580 | init_err_pci_clean: |
7577 | pci_iounmap(pdev, bp->bar0); | 7581 | bnxt_cleanup_pci(bp); |
7578 | pci_release_regions(pdev); | ||
7579 | pci_disable_device(pdev); | ||
7580 | 7582 | ||
7581 | init_err_free: | 7583 | init_err_free: |
7582 | free_netdev(dev); | 7584 | free_netdev(dev); |