Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (i5k_amb, vt8231) Drop uses of pci_read_config_*() return value

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>

authored by

Saheed O. Bolarinwa and committed by
Guenter Roeck
2207515d 2fdf8f7f

+12 -8
+8 -4
drivers/hwmon/i5k_amb.c
··· 427 427 if (!pcidev) 428 428 return -ENODEV; 429 429 430 - if (pci_read_config_dword(pcidev, I5K_REG_AMB_BASE_ADDR, &val32)) 430 + pci_read_config_dword(pcidev, I5K_REG_AMB_BASE_ADDR, &val32); 431 + if (val32 == (u32)~0) 431 432 goto out; 432 433 data->amb_base = val32; 433 434 434 - if (pci_read_config_dword(pcidev, I5K_REG_AMB_LEN_ADDR, &val32)) 435 + pci_read_config_dword(pcidev, I5K_REG_AMB_LEN_ADDR, &val32); 436 + if (val32 == (u32)~0) 435 437 goto out; 436 438 data->amb_len = val32; 437 439 ··· 460 458 if (!pcidev) 461 459 return -ENODEV; 462 460 463 - if (pci_read_config_word(pcidev, I5K_REG_CHAN0_PRESENCE_ADDR, &val16)) 461 + pci_read_config_word(pcidev, I5K_REG_CHAN0_PRESENCE_ADDR, &val16); 462 + if (val16 == (u16)~0) 464 463 goto out; 465 464 amb_present[0] = val16; 466 465 467 - if (pci_read_config_word(pcidev, I5K_REG_CHAN1_PRESENCE_ADDR, &val16)) 466 + pci_read_config_word(pcidev, I5K_REG_CHAN1_PRESENCE_ADDR, &val16); 467 + if (val16 == (u16)~0) 468 468 goto out; 469 469 amb_present[1] = val16; 470 470
+4 -4
drivers/hwmon/vt8231.c
··· 992 992 return -ENODEV; 993 993 } 994 994 995 - if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_BASE_REG, 996 - &val)) 995 + pci_read_config_word(dev, VT8231_BASE_REG, &val); 996 + if (val == (u16)~0) 997 997 return -ENODEV; 998 998 999 999 address = val & ~(VT8231_EXTENT - 1); ··· 1002 1002 return -ENODEV; 1003 1003 } 1004 1004 1005 - if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_ENABLE_REG, 1006 - &val)) 1005 + pci_read_config_word(dev, VT8231_ENABLE_REG, &val); 1006 + if (val == (u16)~0) 1007 1007 return -ENODEV; 1008 1008 1009 1009 if (!(val & 0x0001)) {