@@ -730,9 +730,11 @@ static int peak_pciefd_probe(struct pci_dev *pdev,
goto err_disable_pci;
/* the number of channels depends on sub-system id */
- err = pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &sub_sys_id);
- if (err)
+ pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &sub_sys_id);
+ if (sub_sys_id == (u16)~0) {
+ err = -ENODEV;
goto err_release_regions;
+ }
dev_dbg(&pdev->dev, "probing device %04x:%04x:%04x\n",
pdev->vendor, pdev->device, sub_sys_id);
@@ -560,9 +560,11 @@ static int peak_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
if (err)
goto failure_disable_pci;
- err = pci_read_config_word(pdev, 0x2e, &sub_sys_id);
- if (err)
+ pci_read_config_word(pdev, 0x2e, &sub_sys_id);
+ if (sub_sys_id == (u16)~0) {
+ err = -ENODEV;
goto failure_release_regions;
+ }
dev_dbg(&pdev->dev, "probing device %04x:%04x:%04x\n",
pdev->vendor, pdev->device, sub_sys_id);
@@ -505,7 +505,8 @@ static int eeprom_wait_ready(struct pci_dev *pdev, u32 *status)
* to 1 prior to starting a single byte read/write
*/
for (i = 0; i < MAX_NUM_REGISTER_POLLS; i++) {
- if (pci_read_config_dword(pdev, LBCIF_DWORD1_GROUP, ®))
+ pci_read_config_dword(pdev, LBCIF_DWORD1_GROUP, ®);
+ if (reg == (u32)~0)
return -EIO;
/* I2C idle and Phy Queue Avail both true */
@@ -679,7 +680,8 @@ static int et131x_init_eeprom(struct et131x_adapter *adapter)
* function, because I thought there could be some time conditions
* but it didn't work. Call the whole function twice also work.
*/
- if (pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS, &eestatus)) {
+ pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS, &eestatus);
+ if (eestatus == (u8)~0) {
dev_err(&pdev->dev,
"Could not read PCI config space for EEPROM Status\n");
return -EIO;
@@ -3059,8 +3061,9 @@ static int et131x_pci_init(struct et131x_adapter *adapter,
}
for (i = 0; i < ETH_ALEN; i++) {
- if (pci_read_config_byte(pdev, ET1310_PCI_MAC_ADDRESS + i,
- adapter->rom_addr + i)) {
+ pci_read_config_byte(pdev, ET1310_PCI_MAC_ADDRESS + i,
+ adapter->rom_addr + i);
+ if (*(adapter->rom_addr + i) == (u8)~0) {
dev_err(&pdev->dev, "Could not read PCI config space for MAC address\n");
goto err_out;
}
@@ -1463,14 +1463,15 @@ static int bnx2x_nvram_read32(struct bnx2x *bp, u32 offset, u32 *buf,
static bool bnx2x_is_nvm_accessible(struct bnx2x *bp)
{
- int rc = 1;
+ bool rc = true;
u16 pm = 0;
struct net_device *dev = pci_get_drvdata(bp->pdev);
if (bp->pdev->pm_cap)
- rc = pci_read_config_word(bp->pdev,
+ pci_read_config_word(bp->pdev,
bp->pdev->pm_cap + PCI_PM_CTRL, &pm);
+ rc = (pm == (u16)~0);
if ((rc && !netif_running(dev)) ||
(!rc && ((pm & PCI_PM_CTRL_STATE_MASK) != (__force u16)PCI_D0)))
return false;
@@ -1162,8 +1162,8 @@ static int cn23xx_get_pf_num(struct octeon_device *oct)
ret = 0;
/** Read Function Dependency Link reg to get the function number */
- if (pci_read_config_dword(oct->pci_dev, CN23XX_PCIE_SRIOV_FDL,
- &fdl_bit) == 0) {
+ pci_read_config_dword(oct->pci_dev, CN23XX_PCIE_SRIOV_FDL, &fdl_bit);
+ if (fdl_bit != (u32)~0) {
oct->pf_num = ((fdl_bit >> CN23XX_PCIE_SRIOV_FDL_BIT_POS) &
CN23XX_PCIE_SRIOV_FDL_MASK);
} else {
@@ -4964,8 +4964,9 @@ static int sky2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
* other PCI access through shared memory for speed and to
* avoid MMCONFIG problems.
*/
- err = pci_read_config_dword(pdev, PCI_DEV_REG2, ®);
- if (err) {
+ pci_read_config_dword(pdev, PCI_DEV_REG2, ®);
+ if (reg == (u32)~0) {
+ err = -ENODEV;
dev_err(&pdev->dev, "PCI read config failed\n");
goto err_out_disable;
}
@@ -52,12 +52,7 @@ static int read_vendor_id(struct mlx4_dev *dev)
u16 vendor_id = 0;
int ret;
- ret = pci_read_config_word(dev->persist->pdev, 0, &vendor_id);
- if (ret) {
- mlx4_err(dev, "Failed to read vendor ID, ret=%d\n", ret);
- return ret;
- }
-
+ pci_read_config_word(dev->persist->pdev, 0, &vendor_id);
if (vendor_id == 0xffff) {
mlx4_err(dev, "PCI can't be accessed to read vendor id\n");
return -EINVAL;
@@ -81,8 +81,9 @@ int mlx4_reset(struct mlx4_dev *dev)
for (i = 0; i < 64; ++i) {
if (i == 22 || i == 23)
continue;
- if (pci_read_config_dword(dev->persist->pdev, i * 4,
- hca_header + i)) {
+ pci_read_config_dword(dev->persist->pdev, i * 4,
+ hca_header + i);
+ if (*(hca_header + i) == (u32)~0) {
err = -ENODEV;
mlx4_err(dev, "Couldn't save HCA PCI header, aborting\n");
goto out;
@@ -124,8 +125,9 @@ int mlx4_reset(struct mlx4_dev *dev)
end = jiffies + MLX4_RESET_TIMEOUT_JIFFIES;
do {
- if (!pci_read_config_word(dev->persist->pdev, PCI_VENDOR_ID,
- &vendor) && vendor != 0xffff)
+ pci_read_config_word(dev->persist->pdev, PCI_VENDOR_ID,
+ &vendor);
+ if (vendor != 0xffff)
break;
msleep(1);
@@ -3090,8 +3090,8 @@ static void myri10ge_enable_ecrc(struct myri10ge_priv *mgp)
if (!cap)
return;
- ret = pci_read_config_dword(bridge, cap + PCI_ERR_CAP, &err_cap);
- if (ret) {
+ pci_read_config_dword(bridge, cap + PCI_ERR_CAP, &err_cap);
+ if (err_cap == (u32)~0) {
dev_err(dev, "failed reading ext-conf-space of %s\n",
pci_name(bridge));
dev_err(dev, "\t pci=nommconf in use? "
@@ -678,8 +678,9 @@ fst_cpureset(struct fst_card_info *card)
unsigned int regval;
if (card->family == FST_FAMILY_TXU) {
- if (pci_read_config_byte
- (card->device, PCI_INTERRUPT_LINE, &interrupt_line_register)) {
+ pci_read_config_byte
+ (card->device, PCI_INTERRUPT_LINE, &interrupt_line_register);
+ if (interrupt_line_register == (u8)~0) {
dbg(DBG_ASS,
"Error in reading interrupt line register\n");
}
@@ -544,8 +544,8 @@ brcmf_pcie_select_core(struct brcmf_pciedev_info *devinfo, u16 coreid)
if (core) {
bar0_win = core->base;
pci_write_config_dword(pdev, BRCMF_PCIE_BAR0_WINDOW, bar0_win);
- if (pci_read_config_dword(pdev, BRCMF_PCIE_BAR0_WINDOW,
- &bar0_win) == 0) {
+ pci_read_config_dword(pdev, BRCMF_PCIE_BAR0_WINDOW, &bar0_win);
+ if (bar0_win != (u32)~0) {
if (bar0_win != core->base) {
bar0_win = core->base;
pci_write_config_dword(pdev,
@@ -122,7 +122,8 @@ void iwl_trans_pcie_dump_regs(struct iwl_trans *trans)
sprintf(prefix, "iwlwifi %s: ", pci_name(pdev));
IWL_ERR(trans, "iwlwifi device config registers:\n");
for (i = 0, ptr = buf; i < PCI_DUMP_SIZE; i += 4, ptr++)
- if (pci_read_config_dword(pdev, i, ptr))
+ pci_read_config_dword(pdev, i, ptr);
+ if (*ptr == (u32)~0)
goto err_read;
print_hex_dump(KERN_ERR, prefix, DUMP_PREFIX_OFFSET, 32, 4, buf, i, 0);
@@ -135,7 +136,8 @@ void iwl_trans_pcie_dump_regs(struct iwl_trans *trans)
if (pos) {
IWL_ERR(trans, "iwlwifi device AER capability structure:\n");
for (i = 0, ptr = buf; i < PCI_ERR_ROOT_COMMAND; i += 4, ptr++)
- if (pci_read_config_dword(pdev, pos + i, ptr))
+ pci_read_config_dword(pdev, pos + i, ptr);
+ if (*ptr == (u32)~0)
goto err_read;
print_hex_dump(KERN_ERR, prefix, DUMP_PREFIX_OFFSET,
32, 4, buf, i, 0);
@@ -151,7 +153,8 @@ void iwl_trans_pcie_dump_regs(struct iwl_trans *trans)
IWL_ERR(trans, "iwlwifi parent port (%s) config registers:\n",
pci_name(pdev));
for (i = 0, ptr = buf; i < PCI_PARENT_DUMP_SIZE; i += 4, ptr++)
- if (pci_read_config_dword(pdev, i, ptr))
+ pci_read_config_dword(pdev, i, ptr);
+ if (*ptr == (u32)~0)
goto err_read;
print_hex_dump(KERN_ERR, prefix, DUMP_PREFIX_OFFSET, 32, 4, buf, i, 0);
@@ -165,7 +168,8 @@ void iwl_trans_pcie_dump_regs(struct iwl_trans *trans)
pci_name(pdev));
sprintf(prefix, "iwlwifi %s: ", pci_name(pdev));
for (i = 0, ptr = buf; i <= PCI_ERR_ROOT_ERR_SRC; i += 4, ptr++)
- if (pci_read_config_dword(pdev, pos + i, ptr))
+ pci_read_config_dword(pdev, pos + i, ptr);
+ if (*ptr == (u32)~0)
goto err_read;
print_hex_dump(KERN_ERR, prefix, DUMP_PREFIX_OFFSET, 32,
4, buf, i, 0);
@@ -2191,8 +2195,9 @@ static int iwl_trans_pcie_write_mem(struct iwl_trans *trans, u32 addr,
static int iwl_trans_pcie_read_config32(struct iwl_trans *trans, u32 ofs,
u32 *val)
{
- return pci_read_config_dword(IWL_TRANS_GET_PCIE_TRANS(trans)->pci_dev,
+ pci_read_config_dword(IWL_TRANS_GET_PCIE_TRANS(trans)->pci_dev,
ofs, val);
+ return (*val == (u32)~0) ? -ENODEV : 0;
}
static void iwl_trans_pcie_freeze_txq_timer(struct iwl_trans *trans,
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@helgaas.com> Signed-off-by: Saheed O. Bolarinwa <refactormyself@gmail.com> --- drivers/net/can/peak_canfd/peak_pciefd_main.c | 6 ++++-- drivers/net/can/sja1000/peak_pci.c | 6 ++++-- drivers/net/ethernet/agere/et131x.c | 11 +++++++---- .../net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c | 5 +++-- .../ethernet/cavium/liquidio/cn23xx_pf_device.c | 4 ++-- drivers/net/ethernet/marvell/sky2.c | 5 +++-- drivers/net/ethernet/mellanox/mlx4/catas.c | 7 +------ drivers/net/ethernet/mellanox/mlx4/reset.c | 10 ++++++---- drivers/net/ethernet/myricom/myri10ge/myri10ge.c | 4 ++-- drivers/net/wan/farsync.c | 5 +++-- .../wireless/broadcom/brcm80211/brcmfmac/pcie.c | 4 ++-- drivers/net/wireless/intel/iwlwifi/pcie/trans.c | 15 ++++++++++----- 12 files changed, 47 insertions(+), 35 deletions(-)