[PATCH 2/4] pci: fix DT node matching when reg encodes a non-zero bus number

Sascha Hauer <[email protected]>
Newsgroups org.infradead.lists.barebox
Message-ID <[email protected]>
pci_of_match_device() compared (reg[0] >> 8) & 0xffff against devfn, but
devfn is only 8 bits. The standard PCI DT binding encodes the bus number
in bits [23:16] of reg[0], so any child node with a non-zero bus byte -
which is the common upstream convention - yielded (bus << 8) | devfn and
never matched a plain devfn. For a typical host -> root port -> endpoint
DT nesting (e.g. pci@0,0 { reg = <0x300000 ...>; ethernet@0,0 { reg =
<0x310000 ...>; }; }), the root port match failed and scanning never
reached the endpoint, so endpoint properties like local-mac-address were
never picked up.

Mask with 0xff to match only the devfn byte, like Linux's
of_pci_get_devfn().

Assisted-by: Claude Opus 4.7
Signed-off-by: Sascha Hauer <[email protected]>
---
 drivers/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 32624fe05b..8d18889109 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -558,7 +558,7 @@ pci_of_match_device(struct device *parent, unsigned int devfn)
 			 * address, other properties are defined by the
 			 * PCI/OF node topology.
 			 */
-			reg = (reg >> 8) & 0xffff;
+			reg = (reg >> 8) & 0xff;
 			if (reg == devfn)
 				return np;
 		}

-- 
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.