[RFC PATCH 14/17] IB: Drop uses of pci_read_config_*() return value

From: Saheed O. Bolarinwa
Date: Sat Aug 01 2020 - 08:25:13 EST


The return value of pci_read_config_*() may not indicate a device error.
However, the value read by these functions is more likely to indicate
this kind of error. This presents two overlapping ways of reporting
errors and complicates error checking.

It is possible to move to one single way of checking for error if the
dependency on the return value of these functions is removed, then it
can later be made to return void.

Remove all uses of the return value of pci_read_config_*().
Check the actual value read for ~0. In this case, ~0 is an invalid
value thus it indicates some kind of error.

Suggested-by: Bjorn Helgaas <bjorn@xxxxxxxxxxx>
Signed-off-by: Saheed O. Bolarinwa <refactormyself@xxxxxxxxx>
---
drivers/infiniband/hw/hfi1/pcie.c | 38 +++++++++++------------
drivers/infiniband/hw/mthca/mthca_reset.c | 19 ++++++------
2 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/drivers/infiniband/hw/hfi1/pcie.c b/drivers/infiniband/hw/hfi1/pcie.c
index 1a6268d61977..11cf7dde873d 100644
--- a/drivers/infiniband/hw/hfi1/pcie.c
+++ b/drivers/infiniband/hw/hfi1/pcie.c
@@ -392,24 +392,24 @@ int restore_pci_variables(struct hfi1_devdata *dd)
/* Save BARs and command to rewrite after device reset */
int save_pci_variables(struct hfi1_devdata *dd)
{
- int ret = 0;
+ int ret = -ENODEV;

- ret = pci_read_config_dword(dd->pcidev, PCI_BASE_ADDRESS_0,
+ pci_read_config_dword(dd->pcidev, PCI_BASE_ADDRESS_0,
&dd->pcibar0);
- if (ret)
+ if (dd->pcibar0 == (u32)~0)
goto error;

- ret = pci_read_config_dword(dd->pcidev, PCI_BASE_ADDRESS_1,
+ pci_read_config_dword(dd->pcidev, PCI_BASE_ADDRESS_1,
&dd->pcibar1);
- if (ret)
+ if (dd->pcibar1 == (u32)~0)
goto error;

- ret = pci_read_config_dword(dd->pcidev, PCI_ROM_ADDRESS, &dd->pci_rom);
- if (ret)
+ pci_read_config_dword(dd->pcidev, PCI_ROM_ADDRESS, &dd->pci_rom);
+ if (dd->pci_rom == (u32)~0)
goto error;

- ret = pci_read_config_word(dd->pcidev, PCI_COMMAND, &dd->pci_command);
- if (ret)
+ pci_read_config_word(dd->pcidev, PCI_COMMAND, &dd->pci_command);
+ if (dd->pci_command == (u16)~0)
goto error;

ret = pcie_capability_read_word(dd->pcidev, PCI_EXP_DEVCTL,
@@ -427,14 +427,14 @@ int save_pci_variables(struct hfi1_devdata *dd)
if (ret)
goto error;

- ret = pci_read_config_dword(dd->pcidev, PCI_CFG_MSIX0, &dd->pci_msix0);
- if (ret)
+ pci_read_config_dword(dd->pcidev, PCI_CFG_MSIX0, &dd->pci_msix0);
+ if (dd->pci_command == (u32)~0)
goto error;

if (pci_find_ext_capability(dd->pcidev, PCI_EXT_CAP_ID_TPH)) {
- ret = pci_read_config_dword(dd->pcidev, PCIE_CFG_TPH2,
+ pci_read_config_dword(dd->pcidev, PCIE_CFG_TPH2,
&dd->pci_tph2);
- if (ret)
+ if (dd->pci_tph2 == (u32)~0)
goto error;
}
return 0;
@@ -783,9 +783,9 @@ static int load_eq_table(struct hfi1_devdata *dd, const u8 eq[11][3], u8 fs,
pci_write_config_dword(pdev, PCIE_CFG_REG_PL102,
eq_value(c_minus1, c0, c_plus1));
/* check if these coefficients violate EQ rules */
- ret = pci_read_config_dword(dd->pcidev,
+ pci_read_config_dword(dd->pcidev,
PCIE_CFG_REG_PL105, &violation);
- if (ret) {
+ if (violation == (32)~0) {
dd_dev_err(dd, "Unable to read from PCI config\n");
hit_error = 1;
break;
@@ -1322,8 +1322,8 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd)
/* step 10: decide what to do next */

/* check if we can read PCI space */
- ret = pci_read_config_word(dd->pcidev, PCI_VENDOR_ID, &vendor);
- if (ret) {
+ pci_read_config_word(dd->pcidev, PCI_VENDOR_ID, &vendor);
+ if (vendor == (u16)~0) {
dd_dev_info(dd,
"%s: read of VendorID failed after SBR, err %d\n",
__func__, ret);
@@ -1376,8 +1376,8 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd)
setextled(dd, 0);

/* check for any per-lane errors */
- ret = pci_read_config_dword(dd->pcidev, PCIE_CFG_SPCIE2, &reg32);
- if (ret) {
+ pci_read_config_dword(dd->pcidev, PCIE_CFG_SPCIE2, &reg32);
+ if (reg32 == (u32)~0) {
dd_dev_err(dd, "Unable to read from PCI config\n");
return_error = 1;
goto done;
diff --git a/drivers/infiniband/hw/mthca/mthca_reset.c b/drivers/infiniband/hw/mthca/mthca_reset.c
index 2a6979e4ae1c..5f09d5312472 100644
--- a/drivers/infiniband/hw/mthca/mthca_reset.c
+++ b/drivers/infiniband/hw/mthca/mthca_reset.c
@@ -102,7 +102,10 @@ int mthca_reset(struct mthca_dev *mdev)
for (i = 0; i < 64; ++i) {
if (i == 22 || i == 23)
continue;
- if (pci_read_config_dword(mdev->pdev, i * 4, hca_header + i)) {
+
+ pci_read_config_dword(mdev->pdev, i * 4,
+ hca_header + i);
+ if (*(hca_header + i) == (u32)~0) {
err = -ENODEV;
mthca_err(mdev, "Couldn't save HCA "
"PCI header, aborting.\n");
@@ -123,7 +126,10 @@ int mthca_reset(struct mthca_dev *mdev)
for (i = 0; i < 64; ++i) {
if (i == 22 || i == 23)
continue;
- if (pci_read_config_dword(bridge, i * 4, bridge_header + i)) {
+
+ pci_read_config_dword(bridge, i * 4,
+ bridge_header + i);
+ if (*(bridge_header + i) == (u32)~0) {
err = -ENODEV;
mthca_err(mdev, "Couldn't save HCA bridge "
"PCI header, aborting.\n");
@@ -164,13 +170,8 @@ int mthca_reset(struct mthca_dev *mdev)
int c = 0;

for (c = 0; c < 100; ++c) {
- if (pci_read_config_dword(bridge ? bridge : mdev->pdev, 0, &v)) {
- err = -ENODEV;
- mthca_err(mdev, "Couldn't access HCA after reset, "
- "aborting.\n");
- goto free_bh;
- }
-
+ pci_read_config_dword(bridge ? bridge : mdev->pdev, 0,
+ &v);
if (v != 0xffffffff)
goto good;

--
2.18.4