Skip to contentSkip to conversation

pci: apple: Fix use of uninitialized variable

PATCH In review Mark Kettenis 2 participants 3 messages Aug 23, 2025 – Sep 9, 2025 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci: apple: Fix use of uninitialized variable

Replace use of uninitialized variable with the PCI device number in an error message as this is what we use elsewhere to derive the PCIe port number. Use ofnode_read_pci_addr() to read the PCI address of the node and derive the device number from that.

---
 drivers/pci/pcie_apple.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/pci/pcie_apple.c +13 -5
index 6a8e715d4b6..f5fda9835dc 100644
@@ -246,8 +246,9 @@ static int apple_pcie_setup_port(struct apple_pcie_priv *pcie, ofnode np)
 {
 	struct apple_pcie_port *port;
 	struct gpio_desc reset;
+	struct fdt_pci_addr pci_addr;
 	fdt_addr_t addr;
-	u32 stat, idx;
+	u32 stat;
 	int ret;
 	char name[16];
 
@@ -259,12 +260,13 @@ static int apple_pcie_setup_port(struct apple_pcie_priv *pcie, ofnode np)
 	if (!port)
 		return -ENOMEM;
 
-	ret = ofnode_read_u32_index(np, "reg", 0, &idx);
+	ret = ofnode_read_pci_addr(np, FDT_PCI_SPACE_CONFIG, "reg",
+				   &pci_addr, NULL);
 	if (ret)
 		return ret;
 
 	/* Use the first reg entry to work out the port index */
-	port->idx = idx >> 11;
+	port->idx = PCI_DEV(pci_addr.phys_hi);
 	port->pcie = pcie;
 	port->reset = reset;
 	port->np = np;
@@ -333,9 +335,10 @@ static int apple_pcie_setup_port(struct apple_pcie_priv *pcie, ofnode np)
 static int apple_pcie_probe(struct udevice *dev)
 {
 	struct apple_pcie_priv *pcie = dev_get_priv(dev);
+	struct fdt_pci_addr pci_addr;
 	fdt_addr_t addr;
 	ofnode of_port;
-	int i, ret;
+	int ret;
 
 	pcie->hw = (struct reg_info *)dev_get_driver_data(dev);
 
@@ -357,9 +360,14 @@ static int apple_pcie_probe(struct udevice *dev)
 	     of_port = ofnode_next_subnode(of_port)) {
 		if (!ofnode_is_enabled(of_port))
 			continue;
+		ret = ofnode_read_pci_addr(of_port, FDT_PCI_SPACE_CONFIG,
+					   "reg", &pci_addr, NULL);
+		if (ret)
+			continue;
 		ret = apple_pcie_setup_port(pcie, of_port);
 		if (ret) {
-			dev_err(pcie->dev, "Port %d setup fail: %d\n", i, ret);
+			dev_err(pcie->dev, "Port %d setup fail: %d\n",
+				PCI_DEV(pci_addr.phys_hi), ret);
 			return ret;
 		}
 	}
Signature · 1 line
2.50.1
#1 lore raw
Quoted 6 lines · Mark Kettenis

Replace use of uninitialized variable with the PCI device number in an error message as this is what we use elsewhere to derive the PCIe port number. Use ofnode_read_pci_addr() to read the PCI address of the node and derive the device number from that.

patchwork should pick this up, no need for v2 unless there's real feedback, thanks!

Quoted 66 lines
---
 drivers/pci/pcie_apple.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/pci/pcie_apple.c +13 -5
index 6a8e715d4b6..f5fda9835dc 100644
@@ -246,8 +246,9 @@ static int apple_pcie_setup_port(struct apple_pcie_priv *pcie, ofnode np)
 {
 	struct apple_pcie_port *port;
 	struct gpio_desc reset;
+	struct fdt_pci_addr pci_addr;
 	fdt_addr_t addr;
-	u32 stat, idx;
+	u32 stat;
 	int ret;
 	char name[16];
 
@@ -259,12 +260,13 @@ static int apple_pcie_setup_port(struct apple_pcie_priv *pcie, ofnode np)
 	if (!port)
 		return -ENOMEM;
 
-	ret = ofnode_read_u32_index(np, "reg", 0, &idx);
+	ret = ofnode_read_pci_addr(np, FDT_PCI_SPACE_CONFIG, "reg",
+				   &pci_addr, NULL);
 	if (ret)
 		return ret;
 
 	/* Use the first reg entry to work out the port index */
-	port->idx = idx >> 11;
+	port->idx = PCI_DEV(pci_addr.phys_hi);
 	port->pcie = pcie;
 	port->reset = reset;
 	port->np = np;
@@ -333,9 +335,10 @@ static int apple_pcie_setup_port(struct apple_pcie_priv *pcie, ofnode np)
 static int apple_pcie_probe(struct udevice *dev)
 {
 	struct apple_pcie_priv *pcie = dev_get_priv(dev);
+	struct fdt_pci_addr pci_addr;
 	fdt_addr_t addr;
 	ofnode of_port;
-	int i, ret;
+	int ret;
 
 	pcie->hw = (struct reg_info *)dev_get_driver_data(dev);
 
@@ -357,9 +360,14 @@ static int apple_pcie_probe(struct udevice *dev)
 	     of_port = ofnode_next_subnode(of_port)) {
 		if (!ofnode_is_enabled(of_port))
 			continue;
+		ret = ofnode_read_pci_addr(of_port, FDT_PCI_SPACE_CONFIG,
+					   "reg", &pci_addr, NULL);
+		if (ret)
+			continue;
 		ret = apple_pcie_setup_port(pcie, of_port);
 		if (ret) {
-			dev_err(pcie->dev, "Port %d setup fail: %d\n", i, ret);
+			dev_err(pcie->dev, "Port %d setup fail: %d\n",
+				PCI_DEV(pci_addr.phys_hi), ret);
 			return ret;
 		}
 	}
Signature · 1 line
2.50.1
Signature · 1 line
Tom
#2 lore raw
In reply to Mark Kettenis
Quoted 6 lines · Mark Kettenis

Replace use of uninitialized variable with the PCI device number in an error message as this is what we use elsewhere to derive the PCIe port number. Use ofnode_read_pci_addr() to read the PCI address of the node and derive the device number from that.

Applied to u-boot/next, thanks!

[1/1] pci: apple: Fix use of uninitialized variable

      commit: a5b483a52a5561030ab3e50923a215fbed49d006
Signature · 1 line
Tom