Skip to content

Commit d15f180

Browse files
ij-intelbjorn-helgaas
authored andcommitted
PCI: Do error check on own line to split long "if" conditions
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/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]> [bhelgaas: PCI_POSSIBLE_ERROR()] Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent c287424 commit d15f180

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

drivers/pci/pci.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,15 +732,18 @@ u16 pci_find_vsec_capability(struct pci_dev *dev, u16 vendor, int cap)
732732
{
733733
u16 vsec = 0;
734734
u32 header;
735+
int ret;
735736

736737
if (vendor != dev->vendor)
737738
return 0;
738739

739740
while ((vsec = pci_find_next_ext_capability(dev, vsec,
740741
PCI_EXT_CAP_ID_VNDR))) {
741-
if (pci_read_config_dword(dev, vsec + PCI_VNDR_HEADER,
742-
&header) == PCIBIOS_SUCCESSFUL &&
743-
PCI_VNDR_HEADER_ID(header) == cap)
742+
ret = pci_read_config_dword(dev, vsec + PCI_VNDR_HEADER, &header);
743+
if (ret != PCIBIOS_SUCCESSFUL)
744+
continue;
745+
746+
if (PCI_VNDR_HEADER_ID(header) == cap)
744747
return vsec;
745748
}
746749

drivers/pci/probe.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,15 +1652,15 @@ static void pci_set_removable(struct pci_dev *dev)
16521652
static bool pci_ext_cfg_is_aliased(struct pci_dev *dev)
16531653
{
16541654
#ifdef CONFIG_PCI_QUIRKS
1655-
int pos;
1655+
int pos, ret;
16561656
u32 header, tmp;
16571657

16581658
pci_read_config_dword(dev, PCI_VENDOR_ID, &header);
16591659

16601660
for (pos = PCI_CFG_SPACE_SIZE;
16611661
pos < PCI_CFG_SPACE_EXP_SIZE; pos += PCI_CFG_SPACE_SIZE) {
1662-
if (pci_read_config_dword(dev, pos, &tmp) != PCIBIOS_SUCCESSFUL
1663-
|| header != tmp)
1662+
ret = pci_read_config_dword(dev, pos, &tmp);
1663+
if ((ret != PCIBIOS_SUCCESSFUL) || (header != tmp))
16641664
return false;
16651665
}
16661666

drivers/pci/quirks.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5383,7 +5383,7 @@ int pci_dev_specific_disable_acs_redir(struct pci_dev *dev)
53835383
*/
53845384
static void quirk_intel_qat_vf_cap(struct pci_dev *pdev)
53855385
{
5386-
int pos, i = 0;
5386+
int pos, i = 0, ret;
53875387
u8 next_cap;
53885388
u16 reg16, *cap;
53895389
struct pci_cap_saved_state *state;
@@ -5429,8 +5429,8 @@ static void quirk_intel_qat_vf_cap(struct pci_dev *pdev)
54295429
pdev->pcie_mpss = reg16 & PCI_EXP_DEVCAP_PAYLOAD;
54305430

54315431
pdev->cfg_size = PCI_CFG_SPACE_EXP_SIZE;
5432-
if (pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &status) !=
5433-
PCIBIOS_SUCCESSFUL || (status == 0xffffffff))
5432+
ret = pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &status);
5433+
if ((ret != PCIBIOS_SUCCESSFUL) || (PCI_POSSIBLE_ERROR(status)))
54345434
pdev->cfg_size = PCI_CFG_SPACE_SIZE;
54355435

54365436
if (pci_find_saved_cap(pdev, PCI_CAP_ID_EXP))

0 commit comments

Comments
 (0)