All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
@ 2022-11-18 14:18 Yang Yingliang
  2022-11-18 17:57 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Yang Yingliang @ 2022-11-18 14:18 UTC (permalink / raw)
  To: gregkh, chunfeng.yun; +Cc: linux-usb, yangyingliang

I got the following report:

  OF: ERROR: memory leak, expected refcount 1 instead of 2,
  of_node_get()/of_node_put() unbalanced - destroy cset entry:
  attach overlay node /i2c/pmic@34

The 'parent' returned by fwnode_get_parent() with refcount incremented.
it needs be put after using.

Fixes: 6fadd72943b8 ("usb: roles: get usb-role-switch from parent")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/usb/roles/class.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index dfaed7eee94f..289950e5fcfb 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -106,10 +106,14 @@ usb_role_switch_is_parent(struct fwnode_handle *fwnode)
 	struct fwnode_handle *parent = fwnode_get_parent(fwnode);
 	struct device *dev;
 
-	if (!parent || !fwnode_property_present(parent, "usb-role-switch"))
+	if (!parent || !fwnode_property_present(parent, "usb-role-switch")) {
+		if (parent)
+			fwnode_handle_put(parent);
 		return NULL;
+	}
 
 	dev = class_find_device_by_fwnode(role_class, parent);
+	fwnode_handle_put(parent);
 	return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-19  8:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-18 14:18 [PATCH] usb: roles: fix of node refcount leak in usb_role_switch_is_parent() Yang Yingliang
2022-11-18 17:57 ` Greg KH
2022-11-19  7:47   ` Yang Yingliang
2022-11-19  8:51     ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.