hwmon: (i5k_amb, vt8231) Drop uses of pci_read_config_*() return value
authorSaheed O. Bolarinwa <refactormyself@gmail.com>
Sat, 1 Aug 2020 11:24:39 +0000 (13:24 +0200)
committerGuenter Roeck <linux@roeck-us.net>
Tue, 4 Aug 2020 21:24:39 +0000 (14:24 -0700)
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>
Link: https://lore.kernel.org/r/20200801112446.149549-11-refactormyself@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/i5k_amb.c
drivers/hwmon/vt8231.c

index cd5b62905eee52cc02574b10143409be295b1e04..783fa936e4d167e8668b829a7746bf382c10ee6e 100644 (file)
@@ -427,11 +427,13 @@ static int i5k_find_amb_registers(struct i5k_amb_data *data,
        if (!pcidev)
                return -ENODEV;
 
-       if (pci_read_config_dword(pcidev, I5K_REG_AMB_BASE_ADDR, &val32))
+       pci_read_config_dword(pcidev, I5K_REG_AMB_BASE_ADDR, &val32);
+       if (val32 == (u32)~0)
                goto out;
        data->amb_base = val32;
 
-       if (pci_read_config_dword(pcidev, I5K_REG_AMB_LEN_ADDR, &val32))
+       pci_read_config_dword(pcidev, I5K_REG_AMB_LEN_ADDR, &val32);
+       if (val32 == (u32)~0)
                goto out;
        data->amb_len = val32;
 
@@ -458,11 +460,13 @@ static int i5k_channel_probe(u16 *amb_present, unsigned long dev_id)
        if (!pcidev)
                return -ENODEV;
 
-       if (pci_read_config_word(pcidev, I5K_REG_CHAN0_PRESENCE_ADDR, &val16))
+       pci_read_config_word(pcidev, I5K_REG_CHAN0_PRESENCE_ADDR, &val16);
+       if (val16 == (u16)~0)
                goto out;
        amb_present[0] = val16;
 
-       if (pci_read_config_word(pcidev, I5K_REG_CHAN1_PRESENCE_ADDR, &val16))
+       pci_read_config_word(pcidev, I5K_REG_CHAN1_PRESENCE_ADDR, &val16);
+       if (val16 == (u16)~0)
                goto out;
        amb_present[1] = val16;
 
index 2335d440f72d7b2e0d41c9633c1ff2cfc72534b4..6603727e15a02b8e92f93261f02c61599159c5c7 100644 (file)
@@ -992,8 +992,8 @@ static int vt8231_pci_probe(struct pci_dev *dev,
                        return -ENODEV;
        }
 
-       if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_BASE_REG,
-                                                       &val))
+       pci_read_config_word(dev, VT8231_BASE_REG, &val);
+       if (val == (u16)~0)
                return -ENODEV;
 
        address = val & ~(VT8231_EXTENT - 1);
@@ -1002,8 +1002,8 @@ static int vt8231_pci_probe(struct pci_dev *dev,
                return -ENODEV;
        }
 
-       if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_ENABLE_REG,
-                                                       &val))
+       pci_read_config_word(dev, VT8231_ENABLE_REG, &val);
+       if (val == (u16)~0)
                return -ENODEV;
 
        if (!(val & 0x0001)) {