* [PATCH] PCI: Encode corrected PCIe port type with FIELD_PREP()
@ 2026-11-18 15:35 Gokulkrishna Sekar
0 siblings, 0 replies; only message in thread
From: Gokulkrishna Sekar @ 2026-11-18 15:35 UTC (permalink / raw)
To: linux-pci; +Cc: bhelgaas, mika.westerberg, linux-kernel, Gokulkrishna Sekar
set_pcie_port_type() validates PCIe port topology and corrects
invalid upstream/downstream port type information in the cached
pcie_flags_reg value.
When performing these corrections, the code clears the
PCI_EXP_FLAGS_TYPE field but writes PCI_EXP_TYPE_UPSTREAM or
PCI_EXP_TYPE_DOWNSTREAM directly into pcie_flags_reg. The
PCI_EXP_TYPE_* values are decoded port type numbers, not values
encoded for the PCI_EXP_FLAGS_TYPE bitfield, so the corrected type
is stored in the wrong bit position.
As a result, the cached port type may not match the corrected
topology and subsequent users of pcie_flags_reg can observe an
incorrect PCIe device type.
Use FIELD_PREP(PCI_EXP_FLAGS_TYPE, ...) when updating the cached
field so the corrected port type is encoded consistently with the
format used in the PCI Express Capabilities Register.
Fixes: ca78410403dd ("PCI: Get rid of dev->has_secondary_link flag")
Signed-off-by: Gokulkrishna Sekar <Gokulkrishna.Sekar@harman.com>
---
drivers/pci/probe.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 9a178e0e5f7f..7b09a4463097 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1674,7 +1674,8 @@ void set_pcie_port_type(struct pci_dev *pdev)
if (pcie_downstream_port(parent)) {
pci_info(pdev, "claims to be downstream port but is acting as upstream port, correcting type\n");
pdev->pcie_flags_reg &= ~PCI_EXP_FLAGS_TYPE;
- pdev->pcie_flags_reg |= PCI_EXP_TYPE_UPSTREAM;
+ pdev->pcie_flags_reg |= FIELD_PREP(PCI_EXP_FLAGS_TYPE,
+ PCI_EXP_TYPE_UPSTREAM);
}
} else if (type == PCI_EXP_TYPE_UPSTREAM) {
/*
@@ -1685,7 +1686,8 @@ void set_pcie_port_type(struct pci_dev *pdev)
if (pci_pcie_type(parent) == PCI_EXP_TYPE_UPSTREAM) {
pci_info(pdev, "claims to be upstream port but is acting as downstream port, correcting type\n");
pdev->pcie_flags_reg &= ~PCI_EXP_FLAGS_TYPE;
- pdev->pcie_flags_reg |= PCI_EXP_TYPE_DOWNSTREAM;
+ pdev->pcie_flags_reg |= FIELD_PREP(PCI_EXP_FLAGS_TYPE,
+ PCI_EXP_TYPE_DOWNSTREAM);
}
}
}
--
2.56.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-18 15:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 15:35 [PATCH] PCI: Encode corrected PCIe port type with FIELD_PREP() Gokulkrishna Sekar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®