Skip to contentSkip to conversation

PCI: fix the return value for the pci_find_pcie_root_port()

PATCH In review Ding Tianhong 6 participants 11 messages Aug 17, 2017 – Aug 18, 2017

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

PATCH 1/1 PCI: fix the return value for the pci_find_pcie_root_port()

The pci_find_pcie_root_port() would return NULL if the given dev is already a Root Port, it looks like unfriendly to the PCIe Root Port device, Thierry and Bjorn suggest to let this function return the given dev under this circumstances.

Fixes 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device")
---
 drivers/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci.c +1 -1
index 7e2022f..352bb53 100644
@@ -514,7 +514,7 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
  */
 struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
 {
-	struct pci_dev *bridge, *highest_pcie_bridge = NULL;
+	struct pci_dev *bridge, *highest_pcie_bridge = dev;
 
 	bridge = pci_upstream_bridge(dev);
 	while (bridge && pci_is_pcie(bridge)) {
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw

From: Ding Tianhong <[email protected]>
Date: Thu, 17 Aug 2017 10:25:30 +0800

Quoted 10 lines

The pci_find_pcie_root_port() would return NULL if the given dev is already a Root Port, it looks like unfriendly to the PCIe Root Port device, Thierry and Bjorn suggest to let this function return the given dev under this circumstances.

Fixes 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device")

Bjorn, please review and ACK so Linus doesn't rip my head off again :-)

Thanks.

#2 lore raw
In reply to Ding Tianhong
Quoted 19 lines · Ding Tianhong

The pci_find_pcie_root_port() would return NULL if the given dev is already a Root Port, it looks like unfriendly to the PCIe Root Port device, Thierry and Bjorn suggest to let this function return the given dev under this circumstances.

Fixes 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device")
---
 drivers/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci.c +0 -0
index 7e2022f..352bb53 100644

drivers/pci/pci.c struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res) · line 520

Quoted 8 lines
drivers/pci/pci.c +1 -1
@@ -514,7 +514,7 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
  */
 struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
 {
-	struct pci_dev *bridge, *highest_pcie_bridge = NULL;
+	struct pci_dev *bridge, *highest_pcie_bridge = dev;
 
 	bridge = pci_upstream_bridge(dev);
 	while (bridge && pci_is_pcie(bridge)) {

I think this should actually be this change on top of a revert of commit 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device"). After the above change, the previous fix will have a redundant check because highest_pcie_bridge will never be NULL.

Let me send out that version to clarify what I mean.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170817/f8503237/attachment.sig>

#3 lore raw
Quoted 34 lines · Thierry Reding
Quoted 19 lines · Ding Tianhong

The pci_find_pcie_root_port() would return NULL if the given dev is already a Root Port, it looks like unfriendly to the PCIe Root Port device, Thierry and Bjorn suggest to let this function return the given dev under this circumstances.

Fixes 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device")
---
 drivers/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci.c +0 -0
index 7e2022f..352bb53 100644

drivers/pci/pci.c struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res) · line 520

Quoted 8 lines
drivers/pci/pci.c +1 -1
@@ -514,7 +514,7 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
  */
 struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
 {
-	struct pci_dev *bridge, *highest_pcie_bridge = NULL;
+	struct pci_dev *bridge, *highest_pcie_bridge = dev;
 
 	bridge = pci_upstream_bridge(dev);
 	while (bridge && pci_is_pcie(bridge)) {

I think this should actually be this change on top of a revert of commit 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device"). After the above change, the previous fix will have a redundant check because highest_pcie_bridge will never be NULL.

Quoted 2 lines

Let me send out that version to clarify what I mean.

Hi Thierry:

The patch ("PCI: fix oops when try to find Root Port for a PCI device") has been merge to the linus mainline tree before you found this deficiencies....

Regards
Tianhong

Quoted 2 lines

Thierry

#4 lore raw
Quoted 37 lines · Ding Tianhong
Quoted 34 lines · Thierry Reding
Quoted 19 lines · Ding Tianhong

The pci_find_pcie_root_port() would return NULL if the given dev is already a Root Port, it looks like unfriendly to the PCIe Root Port device, Thierry and Bjorn suggest to let this function return the given dev under this circumstances.

Fixes 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device")
---
 drivers/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci.c +0 -0
index 7e2022f..352bb53 100644

drivers/pci/pci.c struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res) · line 520

Quoted 8 lines
drivers/pci/pci.c +1 -1
@@ -514,7 +514,7 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
  */
 struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
 {
-	struct pci_dev *bridge, *highest_pcie_bridge = NULL;
+	struct pci_dev *bridge, *highest_pcie_bridge = dev;
 
 	bridge = pci_upstream_bridge(dev);
 	while (bridge && pci_is_pcie(bridge)) {

I think this should actually be this change on top of a revert of commit 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device"). After the above change, the previous fix will have a redundant check because highest_pcie_bridge will never be NULL.

Quoted 7 lines
Quoted 2 lines

Let me send out that version to clarify what I mean.

Hi Thierry:

The patch ("PCI: fix oops when try to find Root Port for a PCI device") has been merge to the linus mainline tree before you found this deficiencies....

I understand that. I'm just saying that there's no point keeping that change around because it no longer makes sense after we initialize the highest_pcie_bridge variable to dev.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170817/46f7dea2/attachment-0001.sig>

#5 lore raw
Quoted 41 lines · Thierry Reding
Quoted 40 lines · Ding Tianhong
Quoted 36 lines · Thierry Reding
Quoted 19 lines · Ding Tianhong

The pci_find_pcie_root_port() would return NULL if the given dev is already a Root Port, it looks like unfriendly to the PCIe Root Port device, Thierry and Bjorn suggest to let this function return the given dev under this circumstances.

Fixes 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device")
---
 drivers/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci.c +0 -0
index 7e2022f..352bb53 100644

drivers/pci/pci.c struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res) · line 520

Quoted 8 lines
drivers/pci/pci.c +1 -1
@@ -514,7 +514,7 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
  */
 struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
 {
-	struct pci_dev *bridge, *highest_pcie_bridge = NULL;
+	struct pci_dev *bridge, *highest_pcie_bridge = dev;
 
 	bridge = pci_upstream_bridge(dev);
 	while (bridge && pci_is_pcie(bridge)) {

I think this should actually be this change on top of a revert of commit 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device"). After the above change, the previous fix will have a redundant check because highest_pcie_bridge will never be NULL.

Let me send out that version to clarify what I mean.

Quoted 9 lines
Quoted 4 lines

Hi Thierry:

The patch ("PCI: fix oops when try to find Root Port for a PCI device") has been merge to the linus mainline tree before you found this deficiencies....

I understand that. I'm just saying that there's no point keeping that change around because it no longer makes sense after we initialize the highest_pcie_bridge variable to dev.

Ok, NO problem.:)

Quoted 2 lines

Thierry

#6 lore raw

PATCH 1/1 PCI: Allow PCI express root ports to find themselves

In reply to Ding Tianhong

From: Thierry Reding <[email protected]>

If the pci_find_pcie_root_port() function is called on a root port itself, return the root port rather than NULL.

This effectively reverts commit 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device") which added an extra check that would now be redundant.

Fixes a99b646afa8a ("PCI: Disable PCIe Relaxed Ordering if unsupported")
Fixes c56d4450eb68 ("PCI: Turn off Request Attributes to avoid Chelsio T5 Completion erratum")

---
This applies on top of and was tested on next-20170817.

Michael, it'd be great if you could test this one again to clarify whether or not the fix that's already in Linus' tree is still needed, or whether it's indeed obsoleted by this patch.

 drivers/pci/pci.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/pci/pci.c +4 -5
index b05c587e335a..dd56c1c05614 100644
@@ -514,7 +514,7 @@ EXPORT_SYMBOL(pci_find_resource);
  */
 struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
 {
-	struct pci_dev *bridge, *highest_pcie_bridge = NULL;
+	struct pci_dev *bridge, *highest_pcie_bridge = dev;
 
 	bridge = pci_upstream_bridge(dev);
 	while (bridge && pci_is_pcie(bridge)) {
@@ -522,11 +522,10 @@ struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
 		bridge = pci_upstream_bridge(bridge);
 	}
 
-	if (highest_pcie_bridge &&
-	    pci_pcie_type(highest_pcie_bridge) == PCI_EXP_TYPE_ROOT_PORT)
-		return highest_pcie_bridge;
+	if (pci_pcie_type(highest_pcie_bridge) != PCI_EXP_TYPE_ROOT_PORT)
+		return NULL;
 
-	return NULL;
+	return highest_pcie_bridge;
 }
 EXPORT_SYMBOL(pci_find_pcie_root_port);
 
Signature · 1 line
2.13.3
Acked-by on v1 1/1
#7 lore raw

Re: [PATCH] PCI: Allow PCI express root ports to find themselves

Quoted 5 lines · Thierry Reding

From: Thierry Reding <[email protected]>

If the pci_find_pcie_root_port() function is called on a root port itself, return the root port rather than NULL.

Quoted 7 lines

This effectively reverts commit 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device") which added an extra check that would now be redundant.

Fixes a99b646afa8a ("PCI: Disable PCIe Relaxed Ordering if unsupported")
Fixes c56d4450eb68 ("PCI: Turn off Request Attributes to avoid Chelsio T5 Completion erratum")

I *think* this should work for everybody, but I can't test it personally.

Quoted 46 lines

---
This applies on top of and was tested on next-20170817.

Michael, it'd be great if you could test this one again to clarify whether or not the fix that's already in Linus' tree is still needed, or whether it's indeed obsoleted by this patch.

 drivers/pci/pci.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/pci/pci.c +4 -5
index b05c587e335a..dd56c1c05614 100644
@@ -514,7 +514,7 @@ EXPORT_SYMBOL(pci_find_resource);
  */
 struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
 {
-	struct pci_dev *bridge, *highest_pcie_bridge = NULL;
+	struct pci_dev *bridge, *highest_pcie_bridge = dev;
 
 	bridge = pci_upstream_bridge(dev);
 	while (bridge && pci_is_pcie(bridge)) {
@@ -522,11 +522,10 @@ struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
 		bridge = pci_upstream_bridge(bridge);
 	}
 
-	if (highest_pcie_bridge &&
-	    pci_pcie_type(highest_pcie_bridge) == PCI_EXP_TYPE_ROOT_PORT)
-		return highest_pcie_bridge;
+	if (pci_pcie_type(highest_pcie_bridge) != PCI_EXP_TYPE_ROOT_PORT)
+		return NULL;
 
-	return NULL;
+	return highest_pcie_bridge;
 }
 EXPORT_SYMBOL(pci_find_pcie_root_port);
 
Signature · 7 lines
2.13.3


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Tested-by on v1 1/1
#8 lore raw

Re: [PATCH] PCI: Allow PCI express root ports to find themselves

In reply to Thierry Reding

Hi

Quoted 5 lines · Thierry Reding

From: Thierry Reding <[email protected]>

If the pci_find_pcie_root_port() function is called on a root port itself, return the root port rather than NULL.

Quoted 7 lines

This effectively reverts commit 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device") which added an extra check that would now be redundant.

Fixes a99b646afa8a ("PCI: Disable PCIe Relaxed Ordering if unsupported")
Fixes c56d4450eb68 ("PCI: Turn off Request Attributes to avoid Chelsio T5 Completion erratum")
Quoted 39 lines

---
This applies on top of and was tested on next-20170817.

Michael, it'd be great if you could test this one again to clarify whether or not the fix that's already in Linus' tree is still needed, or whether it's indeed obsoleted by this patch.

  drivers/pci/pci.c | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)
drivers/pci/pci.c +4 -5
index b05c587e335a..dd56c1c05614 100644
@@ -514,7 +514,7 @@ EXPORT_SYMBOL(pci_find_resource);
   */
  struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
  {
-	struct pci_dev *bridge, *highest_pcie_bridge = NULL;
+	struct pci_dev *bridge, *highest_pcie_bridge = dev;
 
  	bridge = pci_upstream_bridge(dev);
  	while (bridge && pci_is_pcie(bridge)) {
@@ -522,11 +522,10 @@ struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
  		bridge = pci_upstream_bridge(bridge);
  	}
 
-	if (highest_pcie_bridge &&
-	    pci_pcie_type(highest_pcie_bridge) == PCI_EXP_TYPE_ROOT_PORT)
-		return highest_pcie_bridge;
+	if (pci_pcie_type(highest_pcie_bridge) != PCI_EXP_TYPE_ROOT_PORT)
+		return NULL;
 
-	return NULL;
+	return highest_pcie_bridge;
  }
  EXPORT_SYMBOL(pci_find_pcie_root_port);
 
#9 lore raw

Re: [PATCH] PCI: Allow PCI express root ports to find themselves

In reply to Thierry Reding
Quoted 12 lines · Thierry Reding

From: Thierry Reding <[email protected]>

If the pci_find_pcie_root_port() function is called on a root port itself, return the root port rather than NULL.

This effectively reverts commit 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device") which added an extra check that would now be redundant.

Fixes a99b646afa8a ("PCI: Disable PCIe Relaxed Ordering if unsupported")
Fixes c56d4450eb68 ("PCI: Turn off Request Attributes to avoid Chelsio T5 Completion erratum")
Quoted 6 lines

---
This applies on top of and was tested on next-20170817.

Michael, it'd be great if you could test this one again to clarify whether or not the fix that's already in Linus' tree is still needed, or whether it's indeed obsoleted by this patch.

This works fine for me, applied on top of Linus' tree (d33a2a914319).

cheers

maintainer Applied
#10 lore raw

Re: [PATCH] PCI: Allow PCI express root ports to find themselves

In reply to Thierry Reding

From: Thierry Reding <[email protected]>
Date: Thu, 17 Aug 2017 13:06:14 +0200

Quoted 12 lines

From: Thierry Reding <[email protected]>

If the pci_find_pcie_root_port() function is called on a root port itself, return the root port rather than NULL.

This effectively reverts commit 0e405232871d6 ("PCI: fix oops when try to find Root Port for a PCI device") which added an extra check that would now be redundant.

Fixes a99b646afa8a ("PCI: Disable PCIe Relaxed Ordering if unsupported")
Fixes c56d4450eb68 ("PCI: Turn off Request Attributes to avoid Chelsio T5 Completion erratum")
Quoted 6 lines

---
This applies on top of and was tested on next-20170817.

Michael, it'd be great if you could test this one again to clarify whether or not the fix that's already in Linus' tree is still needed, or whether it's indeed obsoleted by this patch.

Applied, thanks everyone.