IB/mthca: Clean up error unwind flow in mthca_reset()

The kfree() function was called in a few cases by the mthca_reset()
function during error handling even if the passed variables "bridge_header"
and "hca_header" contained a null pointer.

Adjust jump targets according to the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
This commit is contained in:
Markus Elfring 2016-07-23 11:28:30 +02:00 committed by Doug Ledford
parent 3491ab63b4
commit 380bae5bf2

View File

@ -98,7 +98,7 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENOMEM; err = -ENOMEM;
mthca_err(mdev, "Couldn't allocate memory to save HCA " mthca_err(mdev, "Couldn't allocate memory to save HCA "
"PCI header, aborting.\n"); "PCI header, aborting.\n");
goto out; goto put_dev;
} }
for (i = 0; i < 64; ++i) { for (i = 0; i < 64; ++i) {
@ -108,7 +108,7 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENODEV; err = -ENODEV;
mthca_err(mdev, "Couldn't save HCA " mthca_err(mdev, "Couldn't save HCA "
"PCI header, aborting.\n"); "PCI header, aborting.\n");
goto out; goto free_hca;
} }
} }
@ -121,7 +121,7 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENOMEM; err = -ENOMEM;
mthca_err(mdev, "Couldn't allocate memory to save HCA " mthca_err(mdev, "Couldn't allocate memory to save HCA "
"bridge PCI header, aborting.\n"); "bridge PCI header, aborting.\n");
goto out; goto free_hca;
} }
for (i = 0; i < 64; ++i) { for (i = 0; i < 64; ++i) {
@ -131,7 +131,7 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENODEV; err = -ENODEV;
mthca_err(mdev, "Couldn't save HCA bridge " mthca_err(mdev, "Couldn't save HCA bridge "
"PCI header, aborting.\n"); "PCI header, aborting.\n");
goto out; goto free_bh;
} }
} }
bridge_pcix_cap = pci_find_capability(bridge, PCI_CAP_ID_PCIX); bridge_pcix_cap = pci_find_capability(bridge, PCI_CAP_ID_PCIX);
@ -139,7 +139,7 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENODEV; err = -ENODEV;
mthca_err(mdev, "Couldn't locate HCA bridge " mthca_err(mdev, "Couldn't locate HCA bridge "
"PCI-X capability, aborting.\n"); "PCI-X capability, aborting.\n");
goto out; goto free_bh;
} }
} }
@ -152,7 +152,7 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENOMEM; err = -ENOMEM;
mthca_err(mdev, "Couldn't map HCA reset register, " mthca_err(mdev, "Couldn't map HCA reset register, "
"aborting.\n"); "aborting.\n");
goto out; goto free_bh;
} }
writel(MTHCA_RESET_VALUE, reset); writel(MTHCA_RESET_VALUE, reset);
@ -172,7 +172,7 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENODEV; err = -ENODEV;
mthca_err(mdev, "Couldn't access HCA after reset, " mthca_err(mdev, "Couldn't access HCA after reset, "
"aborting.\n"); "aborting.\n");
goto out; goto free_bh;
} }
if (v != 0xffffffff) if (v != 0xffffffff)
@ -184,7 +184,7 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENODEV; err = -ENODEV;
mthca_err(mdev, "PCI device did not come back after reset, " mthca_err(mdev, "PCI device did not come back after reset, "
"aborting.\n"); "aborting.\n");
goto out; goto free_bh;
} }
good: good:
@ -195,14 +195,14 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENODEV; err = -ENODEV;
mthca_err(mdev, "Couldn't restore HCA bridge Upstream " mthca_err(mdev, "Couldn't restore HCA bridge Upstream "
"split transaction control, aborting.\n"); "split transaction control, aborting.\n");
goto out; goto free_bh;
} }
if (pci_write_config_dword(bridge, bridge_pcix_cap + 0xc, if (pci_write_config_dword(bridge, bridge_pcix_cap + 0xc,
bridge_header[(bridge_pcix_cap + 0xc) / 4])) { bridge_header[(bridge_pcix_cap + 0xc) / 4])) {
err = -ENODEV; err = -ENODEV;
mthca_err(mdev, "Couldn't restore HCA bridge Downstream " mthca_err(mdev, "Couldn't restore HCA bridge Downstream "
"split transaction control, aborting.\n"); "split transaction control, aborting.\n");
goto out; goto free_bh;
} }
/* /*
* Bridge control register is at 0x3e, so we'll * Bridge control register is at 0x3e, so we'll
@ -216,7 +216,7 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENODEV; err = -ENODEV;
mthca_err(mdev, "Couldn't restore HCA bridge reg %x, " mthca_err(mdev, "Couldn't restore HCA bridge reg %x, "
"aborting.\n", i); "aborting.\n", i);
goto out; goto free_bh;
} }
} }
@ -225,7 +225,7 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENODEV; err = -ENODEV;
mthca_err(mdev, "Couldn't restore HCA bridge COMMAND, " mthca_err(mdev, "Couldn't restore HCA bridge COMMAND, "
"aborting.\n"); "aborting.\n");
goto out; goto free_bh;
} }
} }
@ -235,7 +235,7 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENODEV; err = -ENODEV;
mthca_err(mdev, "Couldn't restore HCA PCI-X " mthca_err(mdev, "Couldn't restore HCA PCI-X "
"command register, aborting.\n"); "command register, aborting.\n");
goto out; goto free_bh;
} }
} }
@ -246,7 +246,7 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENODEV; err = -ENODEV;
mthca_err(mdev, "Couldn't restore HCA PCI Express " mthca_err(mdev, "Couldn't restore HCA PCI Express "
"Device Control register, aborting.\n"); "Device Control register, aborting.\n");
goto out; goto free_bh;
} }
linkctl = hca_header[(hca_pcie_cap + PCI_EXP_LNKCTL) / 4]; linkctl = hca_header[(hca_pcie_cap + PCI_EXP_LNKCTL) / 4];
if (pcie_capability_write_word(mdev->pdev, PCI_EXP_LNKCTL, if (pcie_capability_write_word(mdev->pdev, PCI_EXP_LNKCTL,
@ -254,7 +254,7 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENODEV; err = -ENODEV;
mthca_err(mdev, "Couldn't restore HCA PCI Express " mthca_err(mdev, "Couldn't restore HCA PCI Express "
"Link control register, aborting.\n"); "Link control register, aborting.\n");
goto out; goto free_bh;
} }
} }
@ -266,7 +266,7 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENODEV; err = -ENODEV;
mthca_err(mdev, "Couldn't restore HCA reg %x, " mthca_err(mdev, "Couldn't restore HCA reg %x, "
"aborting.\n", i); "aborting.\n", i);
goto out; goto free_bh;
} }
} }
@ -275,13 +275,12 @@ int mthca_reset(struct mthca_dev *mdev)
err = -ENODEV; err = -ENODEV;
mthca_err(mdev, "Couldn't restore HCA COMMAND, " mthca_err(mdev, "Couldn't restore HCA COMMAND, "
"aborting.\n"); "aborting.\n");
goto out;
} }
free_bh:
out:
pci_dev_put(bridge);
kfree(bridge_header); kfree(bridge_header);
free_hca:
kfree(hca_header); kfree(hca_header);
put_dev:
pci_dev_put(bridge);
return err; return err;
} }