[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241020-phy_core_fix-v1-5-078062f7da71@quicinc.com>
Date: Sun, 20 Oct 2024 13:27:50 +0800
From: Zijun Hu <zijun_hu@...oud.com>
To: Vinod Koul <vkoul@...nel.org>,
Kishon Vijay Abraham I <kishon@...nel.org>, Felipe Balbi <balbi@...com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Rob Herring <robh@...nel.org>, Arnd Bergmann <arnd@...db.de>,
Lee Jones <lee@...nel.org>
Cc: Zijun Hu <zijun_hu@...oud.com>, stable@...r.kernel.org,
linux-phy@...ts.infradead.org, netdev@...r.kernel.org,
linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org,
Zijun Hu <quic_zijuhu@...cinc.com>
Subject: [PATCH 5/6] phy: core: Add missing of_node_put() in
of_phy_provider_lookup()
From: Zijun Hu <quic_zijuhu@...cinc.com>
The for_each_child_of_node() macro automatically decrements the child
refcount at the end of every iteration. On early exits, of_node_put()
must be used to manually decrement the refcount and avoid memory leaks.
The macro called by of_phy_provider_lookup() has such early exit, but
it does not call of_node_put() before early exit.
Fixed by adding missing of_node_put() in of_phy_provider_lookup().
Fixes: 2a4c37016ca9 ("phy: core: Fix of_phy_provider_lookup to return PHY provider for sub node")
Cc: stable@...r.kernel.org
Signed-off-by: Zijun Hu <quic_zijuhu@...cinc.com>
---
The impact of this change is wide since of_phy_provider_lookup()
is indirectly called by APIs phy_get(), of_phy_get(), and
devm_of_phy_get_by_index().
The following kernel mainline commit has similar fix:
Commit: b337cc3ce475 ("backlight: lm3509_bl: Fix early returns in for_each_child_of_node()")
---
drivers/phy/phy-core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 967878b78797..24bd619a33dd 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -143,10 +143,11 @@ static struct phy_provider *of_phy_provider_lookup(struct device_node *node)
list_for_each_entry(phy_provider, &phy_provider_list, list) {
if (phy_provider->dev->of_node == node)
return phy_provider;
-
for_each_child_of_node(phy_provider->children, child)
- if (child == node)
+ if (child == node) {
+ of_node_put(child);
return phy_provider;
+ }
}
return ERR_PTR(-EPROBE_DEFER);
--
2.34.1
Powered by blists - more mailing lists