Skip to contentSkip to conversation

pcie aspm link setup, grandparent instead of parent?

PATCH Radim Krčmář 2 participants 3 messages Jun 12, 2013 – Jun 13, 2013 PCI

lore
Share & tools
lore
#0 lore raw

Hello,

as a consequence of hitting a NULL dereference bug[1] while downstream aspm is setting up link_state, I started to wonder why is the code skipping its parent bus in favour of grandparent's link_state.[2]

Is this right? (I have no device to test on ...)

Thanks.

---
1: https://bugzilla.redhat.com/show_bug.cgi?id=972381
The bug is hit because "pdev->bus->parent" has NULL "->parent" and thus NULL "->self".
2: "pdev = bus->self", so "pdev->bus->parent == bus->parent->parent"

drivers/pci/pcie/aspm.c +1 -1
index 403a443..d58e282 100644
@@ -527,7 +527,7 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev)
 	link->pdev = pdev;
 	if (pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM) {
 		struct pcie_link_state *parent;
-		parent = pdev->bus->parent->self->link_state;
+		parent = pdev->bus->self->link_state;
 		if (!parent) {
 			kfree(link);
 			return NULL;
maintainer
#1 lore raw

[+cc linux-pci, Myron, Joe]

Quoted 35 lines · Radim Krčmář

Hello,

as a consequence of hitting a NULL dereference bug[1] while downstream aspm is setting up link_state, I started to wonder why is the code skipping its parent bus in favour of grandparent's link_state.[2]

Is this right? (I have no device to test on ...)

Thanks.

---
1: https://bugzilla.redhat.com/show_bug.cgi?id=972381
The bug is hit because "pdev->bus->parent" has NULL "->parent" and thus NULL "->self".
2: "pdev = bus->self", so "pdev->bus->parent == bus->parent->parent"

drivers/pci/pcie/aspm.c +1 -2
index 403a443..d58e282 100644
@@ -527,7 +527,7 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev)
        link->pdev = pdev;
        if (pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM) {
                struct pcie_link_state *parent;
-               parent = pdev->bus->parent->self->link_state;
+               parent = pdev->bus->self->link_state;
                if (!parent) {
                        kfree(link);
                        return NULL;
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#2 lore raw

2013-06-12 15:54-0600, Bjorn Helgaas:

Quoted 1 line

[+cc linux-pci, Myron, Joe]

I'll remember it.

Quoted 8 lines · Radim Krčmář
Quoted 7 lines

Hello,

as a consequence of hitting a NULL dereference bug[1] while downstream aspm is setting up link_state, I started to wonder why is the code skipping its parent bus in favour of grandparent's link_state.[2]

Is this right? (I have no device to test on ...)

No,
pcie_link_state covers both upstream and downstream port, so we skip upstream port of current device.

Must the "parent device" (grandparent) have valid "->self"? (qemu allows even topologies without the upstream port, so it does not count for much ...)

Quoted 22 lines
Quoted 22 lines

Thanks.

---
1: https://bugzilla.redhat.com/show_bug.cgi?id=972381
The bug is hit because "pdev->bus->parent" has NULL "->parent" and thus NULL "->self".
2: "pdev = bus->self", so "pdev->bus->parent == bus->parent->parent"

drivers/pci/pcie/aspm.c +1 -1
index 403a443..d58e282 100644
@@ -527,7 +527,7 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev)
        link->pdev = pdev;
        if (pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM) {
                struct pcie_link_state *parent;
-               parent = pdev->bus->parent->self->link_state;
+               parent = pdev->bus->self->link_state;
                if (!parent) {
                        kfree(link);
                        return NULL;