Skip to contentSkip to conversation

pci: pci-tegra: fix null pointer assignation.

PATCH Applied [email protected] 3 participants 5 messages Nov 27, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci: pci-tegra: fix null pointer assignation.

From: Chali Anis <[email protected]>

the dev might be null, to be sure we move the dev assignation before the pci parent assignation.

---
 drivers/pci/pci-tegra.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci-tegra.c +1 -1
index b7f8297d153e..dabe63500a4a 100644
@@ -1240,13 +1240,13 @@ static int tegra_pcie_probe(struct device *dev)
 	if (!pcie)
 		return -ENOMEM;
 
+	pcie->dev = dev;
 	pcie->pci.parent = pcie->dev;
 	pci_controller_init(&pcie->pci);
 
 	INIT_LIST_HEAD(&pcie->buses);
 	INIT_LIST_HEAD(&pcie->ports);
 	pcie->soc_data = device_get_match_data(dev);
-	pcie->dev = dev;
 
 	err = tegra_pcie_parse_dt(pcie);
 	if (err < 0) {
#1 lore raw

Hi,

Am Mittwoch, dem 26.11.2025 um 22:40 -0500 schrieb [email protected]:

Quoted 4 lines

From: Chali Anis <[email protected]>

the dev might be null, to be sure we move the dev assignation before the pci parent assignation.

This isn't worded strongly enough. pcie->dev will absolutely be NULL at the point where it is assigned to pci.parent, which seem like a blatant bug and I don't know how this did ever work or if we just ignored the broken parent device connection.

Other than the commit message needing some adjustment, this change looks correct.

Regards,
Lucas

Quoted 26 lines
---
 drivers/pci/pci-tegra.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci-tegra.c +1 -1
index b7f8297d153e..dabe63500a4a 100644
@@ -1240,13 +1240,13 @@ static int tegra_pcie_probe(struct device *dev)
 	if (!pcie)
 		return -ENOMEM;
 
+	pcie->dev = dev;
 	pcie->pci.parent = pcie->dev;
 	pci_controller_init(&pcie->pci);
 
 	INIT_LIST_HEAD(&pcie->buses);
 	INIT_LIST_HEAD(&pcie->ports);
 	pcie->soc_data = device_get_match_data(dev);
-	pcie->dev = dev;
 
 	err = tegra_pcie_parse_dt(pcie);
 	if (err < 0) {
#2 lore raw
Quoted 6 lines · Lucas Stach

Hi,

Am Mittwoch, dem 26.11.2025 um 22:40 -0500 schrieb [email protected]:

Quoted 2 lines

From: Chali Anis <[email protected]>

Quoted 7 lines
Quoted 2 lines

the dev might be null, to be sure we move the dev assignation before the pci parent assignation.

This isn't worded strongly enough. pcie->dev will absolutely be NULL at the point where it is assigned to pci.parent, which seem like a blatant bug and I don't know how this did ever work or if we just ignored the broken parent device connection.

This was broken by:

commit fd3be9d95f342a3d056a08a8e69fe81fd2a35948

Author: Sascha Hauer <[email protected]>
Date:   Tue Mar 26 11:07:37 2024 +0100

pci: add pci_controller_init()

Upcoming patches will add a list to struct pci_controller. To make sure we have a single point to initialize the list introduce a pci_controller_init() and call it from all drivers which use register_pci_controller(). Make sure host->parent is set correctly before calling register_pci_controller() as that will be needed for device tree parsing later.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#3 lore raw
In reply to Lucas Stach
Quoted 6 lines · Lucas Stach

Hi,

Am Mittwoch, dem 26.11.2025 um 22:40 -0500 schrieb [email protected]:

Quoted 2 lines

From: Chali Anis <[email protected]>

Quoted 7 lines
Quoted 2 lines

the dev might be null, to be sure we move the dev assignation before the pci parent assignation.

This isn't worded strongly enough. pcie->dev will absolutely be NULL at the point where it is assigned to pci.parent, which seem like a blatant bug and I don't know how this did ever work or if we just ignored the broken parent device connection.

Reworded to:

pci: pci-tegra: fix null pointer assignation.

By the time we set pcie->pci.parent pcie->dev is null. Initialize it before usage.

Fixes fd3be9d95f34 ("pci: add pci_controller_init()")

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |