Skip to contentSkip to conversation

PCI: imx: fix device node reference leak in imx_pcie_probe

PATCH In review Miaoqian Lin 4 participants 4 messages Sep 3, 2025 – Sep 5, 2025

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

PATCH 1/1 PCI: imx: fix device node reference leak in imx_pcie_probe

As the doc of of_parse_phandle() states:
"The device_node pointer with refcount incremented. Use
* of_node_put() on it when done."
Add missing of_node_put() after of_parse_phandle() call to properly release the device node reference.

Found via static analysis.

Fixes 1df82ec46600 ("PCI: imx: Add workaround for e10728, IMX7d PCIe PLL failure")
---
 drivers/pci/controller/dwc/pci-imx6.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/controller/dwc/pci-imx6.c +1 -0
index 80e48746bbaf..618bc4b08a8b 100644
@@ -1636,6 +1636,7 @@ static int imx_pcie_probe(struct platform_device *pdev)
 		struct resource res;
 
 		ret = of_address_to_resource(np, 0, &res);
+		of_node_put(np);
 		if (ret) {
 			dev_err(dev, "Unable to map PCIe PHY\n");
 			return ret;
Signature · 1 line
2.35.1
#1 lore raw
Quoted 2 lines

Add missing of_node_put() after of_parse_phandle() call to properly release the device node reference.

How do you think about to increase the application of scope-based resource management?
https://elixir.bootlin.com/linux/v6.17-rc4/source/include/linux/of.h#L138

Quoted 1 line

Found via static analysis.

Which concrete software tools would be involved for this purpose?

How do you think about to append parentheses to the function name in the summary phrase?

Regards,
Markus

maintainer
#2 lore raw
In reply to Miaoqian Lin

On Wed, Sep 03, 2025 at 09:51:50PM +0800, Miaoqian Lin wrote:

Subject: PCI: imx: Add missing of_node_put() to fix device node reference leak

Quoted 3 lines

As the doc of of_parse_phandle() states:
"The device_node pointer with refcount incremented. Use
* of_node_put() on it when done."

Needn't this paragaph

Frank

Quoted 27 lines

Add missing of_node_put() after of_parse_phandle() call to properly release the device node reference.

Found via static analysis.

Fixes 1df82ec46600 ("PCI: imx: Add workaround for e10728, IMX7d PCIe PLL failure")
---
 drivers/pci/controller/dwc/pci-imx6.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/controller/dwc/pci-imx6.c +1 -1
index 80e48746bbaf..618bc4b08a8b 100644
@@ -1636,6 +1636,7 @@ static int imx_pcie_probe(struct platform_device *pdev)
 		struct resource res;
 
 		ret = of_address_to_resource(np, 0, &res);
+		of_node_put(np);
 		if (ret) {
 			dev_err(dev, "Unable to map PCIe PHY\n");
 			return ret;
--

2.35.1

#3 lore raw
In reply to Miaoqian Lin
Quoted 5 lines · Miaoqian Lin

As the doc of of_parse_phandle() states:
"The device_node pointer with refcount incremented. Use
* of_node_put() on it when done."
Add missing of_node_put() after of_parse_phandle() call to properly release the device node reference.

How did you verify the node can go after of_address_to_resource()?

Quoted 12 lines
Fixes 1df82ec46600 ("PCI: imx: Add workaround for e10728, IMX7d PCIe PLL failure")
---
  drivers/pci/controller/dwc/pci-imx6.c | 1 +
  1 file changed, 1 insertion(+)
drivers/pci/controller/dwc/pci-imx6.c +0 -0
index 80e48746bbaf..618bc4b08a8b 100644

drivers/pci/controller/dwc/pci-imx6.c static int imx_pcie_probe(struct platform_device *pdev) · line 1639

Quoted 4 lines
drivers/pci/controller/dwc/pci-imx6.c +1 -0
@@ -1636,6 +1636,7 @@ static int imx_pcie_probe(struct platform_device *pdev)
  		struct resource res;
 
  		ret = of_address_to_resource(np, 0, &res);
+		of_node_put(np);

So why not to use __free(device_node)?

thanks,

Signature · 2 lines
js
suse labs