Skip to contentSkip to conversation

PCI: rzg3s-host: Fix device node reference leak in rzg3s_pcie_host_parse_port()

PATCH Applied Felix Gu 4 participants 4 messages Feb 3 – Feb 6

Subsystems (3)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 PCI: rzg3s-host: Fix device node reference leak in rzg3s_pcie_host_parse_port()

In rzg3s_pcie_host_parse_port(), of_get_next_child() returns a device node with an incremented reference count that must be released with of_node_put(). The current code fails to call of_node_put() which causes a reference leak.

Use the __free(device_node) attribute to ensure automatic cleanup when the variable goes out of scope.

Fixes 7ef502fb35b2 ("PCI: Add Renesas RZ/G3S host controller driver")
---
 drivers/pci/controller/pcie-rzg3s-host.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-rzg3s-host.c +2 -1
index 5aa58638903f..2809112e6317 100644
@@ -1142,7 +1142,8 @@ static int rzg3s_pcie_resets_prepare_and_get(struct rzg3s_pcie_host *host)
 
 static int rzg3s_pcie_host_parse_port(struct rzg3s_pcie_host *host)
 {
-	struct device_node *of_port = of_get_next_child(host->dev->of_node, NULL);
+	struct device_node *of_port __free(device_node) =
+		of_get_next_child(host->dev->of_node, NULL);
 	struct rzg3s_pcie_port *port = &host->port;
 	int ret;
 

---
base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d
change-id: 20260204-rzg3s-bc7c27c80a89

Best regards,

Signature · 1 line
Felix Gu <[email protected]>
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 10 lines · Felix Gu

In rzg3s_pcie_host_parse_port(), of_get_next_child() returns a device node with an incremented reference count that must be released with of_node_put(). The current code fails to call of_node_put() which causes a reference leak.

Use the __free(device_node) attribute to ensure automatic cleanup when the variable goes out of scope.

Fixes 7ef502fb35b2 ("PCI: Add Renesas RZ/G3S host controller driver")
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Felix Gu
Quoted 10 lines · Felix Gu

In rzg3s_pcie_host_parse_port(), of_get_next_child() returns a device node with an incremented reference count that must be released with of_node_put(). The current code fails to call of_node_put() which causes a reference leak.

Use the __free(device_node) attribute to ensure automatic cleanup when the variable goes out of scope.

Fixes 7ef502fb35b2 ("PCI: Add Renesas RZ/G3S host controller driver")

Patch LGTM. But we are nearing the merge window. So I'm not sure if Bjorn would be happy for me to merge any patches atm.

Since this fix is trivial, we can defer it for 7.1.

Bjorn, if you decide to merge this still, feel free to add:

On a side note, I see that this driver just parses the first Root Port instead of parsing all Root Port nodes because the current IP design has only one RP. But for uniformity, it should parse all nodes so that if the IP gets extended in the future, driver can still hoepfully work.

This further motivates me to come up with host controller generic APIs to parse the Root Ports :)

- Mani

Quoted 27 lines
---
 drivers/pci/controller/pcie-rzg3s-host.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-rzg3s-host.c +2 -2
index 5aa58638903f..2809112e6317 100644
@@ -1142,7 +1142,8 @@ static int rzg3s_pcie_resets_prepare_and_get(struct rzg3s_pcie_host *host)
 
 static int rzg3s_pcie_host_parse_port(struct rzg3s_pcie_host *host)
 {
-	struct device_node *of_port = of_get_next_child(host->dev->of_node, NULL);
+	struct device_node *of_port __free(device_node) =
+		of_get_next_child(host->dev->of_node, NULL);
 	struct rzg3s_pcie_port *port = &host->port;
 	int ret;
 
 
---

base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d
change-id: 20260204-rzg3s-bc7c27c80a89

Best regards,

Signature · 1 line
Felix Gu <[email protected]>
Signature · 1 line
மணிவண்ணன் சதாசிவம்
#3 lore raw
In reply to Felix Gu
Quoted 10 lines · Felix Gu

In rzg3s_pcie_host_parse_port(), of_get_next_child() returns a device node with an incremented reference count that must be released with of_node_put(). The current code fails to call of_node_put() which causes a reference leak.

Use the __free(device_node) attribute to ensure automatic cleanup when the variable goes out of scope.

Fixes 7ef502fb35b2 ("PCI: Add Renesas RZ/G3S host controller driver")

Applied to pci/controller/rzg3s-host for v6.20, thanks!

It's close to the merge window, but only affects a single driver that's pretty new, so if anything breaks it won't affect many people.

Quoted 27 lines
---
 drivers/pci/controller/pcie-rzg3s-host.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-rzg3s-host.c +2 -2
index 5aa58638903f..2809112e6317 100644
@@ -1142,7 +1142,8 @@ static int rzg3s_pcie_resets_prepare_and_get(struct rzg3s_pcie_host *host)
 
 static int rzg3s_pcie_host_parse_port(struct rzg3s_pcie_host *host)
 {
-	struct device_node *of_port = of_get_next_child(host->dev->of_node, NULL);
+	struct device_node *of_port __free(device_node) =
+		of_get_next_child(host->dev->of_node, NULL);
 	struct rzg3s_pcie_port *port = &host->port;
 	int ret;
 
 
---

base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d
change-id: 20260204-rzg3s-bc7c27c80a89

Best regards,

Signature · 1 line
Felix Gu <[email protected]>