drivers/pci/controller/dwc/pci-imx6.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
In imx_pcie_probe, np is obtained by of_parse_phandle() and must be
released when it's no longer needed. However, it doesn't release the
reference, which cuases a reference leak.
Fix this by using the __free(device_node) cleanup handler to release the
reference when it goes out of scope.
Fixes: 1df82ec46600 ("PCI: imx: Add workaround for e10728, IMX7d PCIe PLL failure")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
Changes in v2:
- Use __free(device_node) clean handler to fix the leak.
- Link to v1: https://lore.kernel.org/r/20260124-pci_imx6-v1-1-6f4379fc5160@gmail.com
---
drivers/pci/controller/dwc/pci-imx6.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index 1d8677d7de04..f459d05ecd7d 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -1643,7 +1643,6 @@ static int imx_pcie_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct dw_pcie *pci;
struct imx_pcie *imx_pcie;
- struct device_node *np;
struct device_node *node = dev->of_node;
int i, ret, domain;
u16 val;
@@ -1670,7 +1669,8 @@ static int imx_pcie_probe(struct platform_device *pdev)
pci->pp.ops = &imx_pcie_host_dw_pme_ops;
/* Find the PHY if one is defined, only imx7d uses it */
- np = of_parse_phandle(node, "fsl,imx7d-pcie-phy", 0);
+ struct device_node *np __free(device_node) =
+ of_parse_phandle(node, "fsl,imx7d-pcie-phy", 0);
if (np) {
struct resource res;
---
base-commit: a0c666c25aeefd16f4b088c6549a6fb6b65a8a1d
change-id: 20260124-pci_imx6-f97d70887dfc
Best regards,
--
Felix Gu <ustc.gu@gmail.com>
On Sat, Jan 24, 2026 at 11:42:45PM +0800, Felix Gu wrote:
> In imx_pcie_probe, np is obtained by of_parse_phandle() and must be
> released when it's no longer needed. However, it doesn't release the
> reference, which cuases a reference leak.
> Fix this by using the __free(device_node) cleanup handler to release the
> reference when it goes out of scope.
>
> Fixes: 1df82ec46600 ("PCI: imx: Add workaround for e10728, IMX7d PCIe PLL failure")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
After fix Bjons's comments.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> Changes in v2:
> - Use __free(device_node) clean handler to fix the leak.
> - Link to v1: https://lore.kernel.org/r/20260124-pci_imx6-v1-1-6f4379fc5160@gmail.com
> ---
> drivers/pci/controller/dwc/pci-imx6.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> index 1d8677d7de04..f459d05ecd7d 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c
> @@ -1643,7 +1643,6 @@ static int imx_pcie_probe(struct platform_device *pdev)
> struct device *dev = &pdev->dev;
> struct dw_pcie *pci;
> struct imx_pcie *imx_pcie;
> - struct device_node *np;
> struct device_node *node = dev->of_node;
> int i, ret, domain;
> u16 val;
> @@ -1670,7 +1669,8 @@ static int imx_pcie_probe(struct platform_device *pdev)
> pci->pp.ops = &imx_pcie_host_dw_pme_ops;
>
> /* Find the PHY if one is defined, only imx7d uses it */
> - np = of_parse_phandle(node, "fsl,imx7d-pcie-phy", 0);
> + struct device_node *np __free(device_node) =
> + of_parse_phandle(node, "fsl,imx7d-pcie-phy", 0);
> if (np) {
> struct resource res;
>
>
> ---
> base-commit: a0c666c25aeefd16f4b088c6549a6fb6b65a8a1d
> change-id: 20260124-pci_imx6-f97d70887dfc
>
> Best regards,
> --
> Felix Gu <ustc.gu@gmail.com>
>
On Sat, Jan 24, 2026 at 11:42:45PM +0800, Felix Gu wrote:
> In imx_pcie_probe, np is obtained by of_parse_phandle() and must be
> released when it's no longer needed. However, it doesn't release the
> reference, which cuases a reference leak.
> Fix this by using the __free(device_node) cleanup handler to release the
> reference when it goes out of scope.
Mani, if you apply this, can you add a blank line between paragraphs
and:
s/imx_pcie_probe,/imx_pcie_probe(),/
s/cuases/causes/
Felix, if you repost this for other reasons, please incorporate those.
> Fixes: 1df82ec46600 ("PCI: imx: Add workaround for e10728, IMX7d PCIe PLL failure")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
> Changes in v2:
> - Use __free(device_node) clean handler to fix the leak.
> - Link to v1: https://lore.kernel.org/r/20260124-pci_imx6-v1-1-6f4379fc5160@gmail.com
> ---
> drivers/pci/controller/dwc/pci-imx6.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> index 1d8677d7de04..f459d05ecd7d 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c
> @@ -1643,7 +1643,6 @@ static int imx_pcie_probe(struct platform_device *pdev)
> struct device *dev = &pdev->dev;
> struct dw_pcie *pci;
> struct imx_pcie *imx_pcie;
> - struct device_node *np;
> struct device_node *node = dev->of_node;
> int i, ret, domain;
> u16 val;
> @@ -1670,7 +1669,8 @@ static int imx_pcie_probe(struct platform_device *pdev)
> pci->pp.ops = &imx_pcie_host_dw_pme_ops;
>
> /* Find the PHY if one is defined, only imx7d uses it */
> - np = of_parse_phandle(node, "fsl,imx7d-pcie-phy", 0);
> + struct device_node *np __free(device_node) =
> + of_parse_phandle(node, "fsl,imx7d-pcie-phy", 0);
> if (np) {
> struct resource res;
>
>
> ---
> base-commit: a0c666c25aeefd16f4b088c6549a6fb6b65a8a1d
> change-id: 20260124-pci_imx6-f97d70887dfc
>
> Best regards,
> --
> Felix Gu <ustc.gu@gmail.com>
>
>
© 2016 - 2026 Red Hat, Inc.