PCI: Do error check on own line to split long "if" conditions
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Mon, 11 Sep 2023 12:53:52 +0000 (15:53 +0300)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 10 Oct 2023 21:40:18 +0000 (16:40 -0500)
Placing PCI error code check inside "if" condition usually results in need
to split lines. Combined with additional conditions the "if" condition
becomes messy.

Convert to the usual error handling pattern with an additional variable to
improve code readability. In addition, reverse the logic in
pci_find_vsec_capability() to get rid of &&.

No functional changes intended.

Link: https://lore.kernel.org/r/20230911125354.25501-5-ilpo.jarvinen@linux.intel.com
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
[bhelgaas: PCI_POSSIBLE_ERROR()]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/pci.c
drivers/pci/probe.c
drivers/pci/quirks.c

index 59c01d6..5e51e8b 100644 (file)
@@ -732,15 +732,18 @@ u16 pci_find_vsec_capability(struct pci_dev *dev, u16 vendor, int cap)
 {
        u16 vsec = 0;
        u32 header;
+       int ret;
 
        if (vendor != dev->vendor)
                return 0;
 
        while ((vsec = pci_find_next_ext_capability(dev, vsec,
                                                     PCI_EXT_CAP_ID_VNDR))) {
-               if (pci_read_config_dword(dev, vsec + PCI_VNDR_HEADER,
-                                         &header) == PCIBIOS_SUCCESSFUL &&
-                   PCI_VNDR_HEADER_ID(header) == cap)
+               ret = pci_read_config_dword(dev, vsec + PCI_VNDR_HEADER, &header);
+               if (ret != PCIBIOS_SUCCESSFUL)
+                       continue;
+
+               if (PCI_VNDR_HEADER_ID(header) == cap)
                        return vsec;
        }
 
index 7955345..4315996 100644 (file)
@@ -1652,15 +1652,15 @@ static void pci_set_removable(struct pci_dev *dev)
 static bool pci_ext_cfg_is_aliased(struct pci_dev *dev)
 {
 #ifdef CONFIG_PCI_QUIRKS
-       int pos;
+       int pos, ret;
        u32 header, tmp;
 
        pci_read_config_dword(dev, PCI_VENDOR_ID, &header);
 
        for (pos = PCI_CFG_SPACE_SIZE;
             pos < PCI_CFG_SPACE_EXP_SIZE; pos += PCI_CFG_SPACE_SIZE) {
-               if (pci_read_config_dword(dev, pos, &tmp) != PCIBIOS_SUCCESSFUL
-                   || header != tmp)
+               ret = pci_read_config_dword(dev, pos, &tmp);
+               if ((ret != PCIBIOS_SUCCESSFUL) || (header != tmp))
                        return false;
        }
 
index eeec1d6..f5fc924 100644 (file)
@@ -5383,7 +5383,7 @@ int pci_dev_specific_disable_acs_redir(struct pci_dev *dev)
  */
 static void quirk_intel_qat_vf_cap(struct pci_dev *pdev)
 {
-       int pos, i = 0;
+       int pos, i = 0, ret;
        u8 next_cap;
        u16 reg16, *cap;
        struct pci_cap_saved_state *state;
@@ -5429,8 +5429,8 @@ static void quirk_intel_qat_vf_cap(struct pci_dev *pdev)
                pdev->pcie_mpss = reg16 & PCI_EXP_DEVCAP_PAYLOAD;
 
                pdev->cfg_size = PCI_CFG_SPACE_EXP_SIZE;
-               if (pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &status) !=
-                   PCIBIOS_SUCCESSFUL || (status == 0xffffffff))
+               ret = pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &status);
+               if ((ret != PCIBIOS_SUCCESSFUL) || (PCI_POSSIBLE_ERROR(status)))
                        pdev->cfg_size = PCI_CFG_SPACE_SIZE;
 
                if (pci_find_saved_cap(pdev, PCI_CAP_ID_EXP))