Message ID | 20221118141850.806564-1-yangyingliang@huawei.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | usb: roles: fix of node refcount leak in usb_role_switch_is_parent() | expand |
On Fri, Nov 18, 2022 at 10:18:50PM +0800, Yang Yingliang wrote: > 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 report from what? What generates this?
On 2022/11/19 1:57, Greg KH wrote: > On Fri, Nov 18, 2022 at 10:18:50PM +0800, Yang Yingliang wrote: >> 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 > report from what? What generates this? I got this report while doing loading device (mt6370-tcpc) test with CONFIG_OF_UNITTEST and CONFIG_OF_DYNAMIC enabled. Thanks, Yang > > .
On Sat, Nov 19, 2022 at 03:47:33PM +0800, Yang Yingliang wrote: > > On 2022/11/19 1:57, Greg KH wrote: > > On Fri, Nov 18, 2022 at 10:18:50PM +0800, Yang Yingliang wrote: > > > 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 > > report from what? What generates this? > I got this report while doing loading device (mt6370-tcpc) test > with CONFIG_OF_UNITTEST and CONFIG_OF_DYNAMIC enabled. Please include that in the information in the changelog text and resubmit a v2. thanks, greg k-h
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); }
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(-)