From: Vladimir Oltean <olteanv@gmail.com>
To: Haotian Zhang <vulab@iscas.ac.cn>
Cc: vkoul@kernel.org, kishon@kernel.org,
andriy.shevchenko@linux.intel.com, linux-phy@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] phy: hisilicon: Fix OF node reference leak
Date: Mon, 16 Feb 2026 10:43:48 +0200 [thread overview]
Message-ID: <20260216084348.e2ozdqy5unvfs7qe@skbuf> (raw)
In-Reply-To: <20251112062246.852-1-vulab@iscas.ac.cn>
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@iscas.ac.cn>
> ---
> 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?
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
next prev parent reply other threads:[~2026-02-16 8:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-12 6:22 [PATCH] phy: hisilicon: Fix OF node reference leak Haotian Zhang
2026-02-16 8:43 ` Vladimir Oltean [this message]
2026-02-16 9:09 ` Andy Shevchenko
2026-02-16 9:11 ` Andy Shevchenko
2026-02-19 16:38 ` [PATCH v2] phy: hisilicon: hi3670: Fix OF node and device reference leaks Haotian Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260216084348.e2ozdqy5unvfs7qe@skbuf \
--to=olteanv@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=kishon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=vkoul@kernel.org \
--cc=vulab@iscas.ac.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox