[PATCH 4/6] phy: core: Add missing of_node_put() for an error handling path of _of_phy_get()

Zijun Hu posted 6 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH 4/6] phy: core: Add missing of_node_put() for an error handling path of _of_phy_get()
Posted by Zijun Hu 1 month, 1 week ago
From: Zijun Hu <quic_zijuhu@quicinc.com>

It is wrong for _of_phy_get()  not to decrease the OF node refcount which
was increased by previous of_parse_phandle_with_args() when returns due to
of_device_is_compatible() error.

Fixed by adding of_node_put() before the error return.

Fixes: b7563e2796f8 ("phy: work around 'phys' references to usb-nop-xceiv devices")
Cc: stable@vger.kernel.org
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/phy/phy-core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 52ca590a58b9..967878b78797 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -629,8 +629,11 @@ static struct phy *_of_phy_get(struct device_node *np, int index)
 		return ERR_PTR(-ENODEV);
 
 	/* This phy type handled by the usb-phy subsystem for now */
-	if (of_device_is_compatible(args.np, "usb-nop-xceiv"))
+	if (of_device_is_compatible(args.np, "usb-nop-xceiv")) {
+		/* Put refcount above of_parse_phandle_with_args() got */
+		of_node_put(args.np);
 		return ERR_PTR(-ENODEV);
+	}
 
 	mutex_lock(&phy_provider_mutex);
 	phy_provider = of_phy_provider_lookup(args.np);

-- 
2.34.1