[PATCH] phy: core: fix an OF node reference leak in _of_phy_get()

Joe Hattori joe at pf.is.s.u-tokyo.ac.jp
Wed Dec 11 18:11:10 PST 2024


_of_phy_get() does not decrement the refcount of the obtained OF node in
the error path. Add a of_node_put() call before returning.

This bug was found by an experimental static analysis tool that I am
developing.

Fixes: b7563e2796f8 ("phy: work around 'phys' references to usb-nop-xceiv devices")
Signed-off-by: Joe Hattori <joe at pf.is.s.u-tokyo.ac.jp>
---
 drivers/phy/phy-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index f053b525ccff..bca303d51fd2 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -629,8 +629,10 @@ 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")) {
+		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




More information about the linux-phy mailing list