Re: [PATCH] phy: hisilicon: Fix OF node reference leak
From: Vladimir Oltean
Date: Mon Feb 16 2026 - 03:44:00 EST
Hello Haotian,
On Wed, Nov 12, 2025 at 02:22:46PM +0800, Haotian Zhang wrote:
> hi3670_pcie_get_resources_from_pcie() leaks an OF node reference
> obtained by of_get_child_by_name(). The reference is not released
> on any of the error paths or on successful return, causing a
> reference count leak.
>
> Fix this by declaring the device node with the __free(device_node)
> cleanup construct to ensure the reference is automatically released.
>
> Fixes: 73075011ffff ("phy: HiSilicon: Add driver for Kirin 970 PCIe PHY")
> Signed-off-by: Haotian Zhang <vulab@xxxxxxxxxxx>
> ---
> drivers/phy/hisilicon/phy-hi3670-pcie.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/phy/hisilicon/phy-hi3670-pcie.c b/drivers/phy/hisilicon/phy-hi3670-pcie.c
> index dbc7dcce682b..fc4f50aa31cd 100644
> --- a/drivers/phy/hisilicon/phy-hi3670-pcie.c
> +++ b/drivers/phy/hisilicon/phy-hi3670-pcie.c
> @@ -558,11 +558,10 @@ static int hi3670_pcie_noc_power(struct hi3670_pcie_phy *phy, bool enable)
>
> static int hi3670_pcie_get_resources_from_pcie(struct hi3670_pcie_phy *phy)
> {
> - struct device_node *pcie_port;
> struct device *dev = phy->dev;
> struct device *pcie_dev;
> -
> - pcie_port = of_get_child_by_name(dev->parent->of_node, "pcie");
> + struct device_node *pcie_port __free(device_node) =
> + of_get_child_by_name(dev->parent->of_node, "pcie");
> if (!pcie_port) {
> dev_err(dev, "no pcie node found in %s\n",
> dev->parent->of_node->full_name);
> --
> 2.50.1.windows.1
>
>
Sorry for the delay, and thank you for the patch.
Please do not complicate the solution more than necessary, and more
importantly, do not use cleanup.h infrastructure added in 2023 to fix a
bug from 2021 (will be difficult to backport).
In this case, it is sufficient to free the OF node after
bus_find_device_by_of_node():
pcie_port = of_get_child_by_name(dev->parent->of_node, "pcie");
if (!pcie_port) {
dev_err(dev, "no pcie node found in %s\n",
dev->parent->of_node->full_name);
return -ENODEV;
}
pcie_dev = bus_find_device_by_of_node(&platform_bus_type, pcie_port);
+ of_node_put(pcie_port);
if (!pcie_dev) {
dev_err(dev, "Didn't find pcie device\n");
return -ENODEV;
}
Note that there exists a second reference leak bug in the same function.
bus_find_device_by_of_node() requires put_device(pcie_dev) after it is
no longer needed.
Can you resubmit a patch set addressing both issues?