* [PATCH v3] usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
@ 2022-11-21 14:46 Yang Yingliang
2022-11-22 8:33 ` Heikki Krogerus
0 siblings, 1 reply; 4+ messages in thread
From: Yang Yingliang @ 2022-11-21 14:46 UTC (permalink / raw)
To: gregkh, chunfeng.yun, heikki.krogerus; +Cc: linux-usb, yangyingliang
I got the following report while doing device(mt6370-tcpc) load
test with CONFIG_OF_UNITTEST and CONFIG_OF_DYNAMIC enabled:
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")
Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
v2 -> v3:
Remove not needed null pointer check.
v1 -> v2:
Add description to how is the report generated.
---
drivers/usb/roles/class.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index dfaed7eee94f..0650295f261c 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -106,10 +106,13 @@ 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")) {
+ 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
* Re: [PATCH v3] usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
2022-11-21 14:46 [PATCH v3] usb: roles: fix of node refcount leak in usb_role_switch_is_parent() Yang Yingliang
@ 2022-11-22 8:33 ` Heikki Krogerus
2022-11-22 8:47 ` Yang Yingliang
0 siblings, 1 reply; 4+ messages in thread
From: Heikki Krogerus @ 2022-11-22 8:33 UTC (permalink / raw)
To: Yang Yingliang; +Cc: gregkh, chunfeng.yun, linux-usb
Hi,
On Mon, Nov 21, 2022 at 10:46:20PM +0800, Yang Yingliang wrote:
> I got the following report while doing device(mt6370-tcpc) load
> test with CONFIG_OF_UNITTEST and CONFIG_OF_DYNAMIC enabled:
>
> 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")
> Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
That's not the appropriate tag in this case. I have not suggested
this patch.
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> v2 -> v3:
> Remove not needed null pointer check.
>
> v1 -> v2:
> Add description to how is the report generated.
> ---
> drivers/usb/roles/class.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index dfaed7eee94f..0650295f261c 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -106,10 +106,13 @@ 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")) {
Please change that as well like I proposed earlier:
if (!fwnode_property_present(parent, "usb-role-switch")) {
You don't need to check the parent separately.
> + 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);
> }
>
thanks,
--
heikki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
2022-11-22 8:33 ` Heikki Krogerus
@ 2022-11-22 8:47 ` Yang Yingliang
2022-11-22 9:02 ` Heikki Krogerus
0 siblings, 1 reply; 4+ messages in thread
From: Yang Yingliang @ 2022-11-22 8:47 UTC (permalink / raw)
To: Heikki Krogerus; +Cc: gregkh, chunfeng.yun, linux-usb, yangyingliang
On 2022/11/22 16:33, Heikki Krogerus wrote:
> Hi,
>
> On Mon, Nov 21, 2022 at 10:46:20PM +0800, Yang Yingliang wrote:
>> I got the following report while doing device(mt6370-tcpc) load
>> test with CONFIG_OF_UNITTEST and CONFIG_OF_DYNAMIC enabled:
>>
>> 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")
>> Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> That's not the appropriate tag in this case. I have not suggested
> this patch.
>
>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>> ---
>> v2 -> v3:
>> Remove not needed null pointer check.
>>
>> v1 -> v2:
>> Add description to how is the report generated.
>> ---
>> drivers/usb/roles/class.c | 5 ++++-
>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
>> index dfaed7eee94f..0650295f261c 100644
>> --- a/drivers/usb/roles/class.c
>> +++ b/drivers/usb/roles/class.c
>> @@ -106,10 +106,13 @@ 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")) {
> Please change that as well like I proposed earlier:
>
> if (!fwnode_property_present(parent, "usb-role-switch")) {
>
> You don't need to check the parent separately.
Yes, fwnode_property_present() has already checked the parent, the
parent check can be removed.
Need I add your suggest tag when I send v4 to change it as above.
Thanks,
Yang
>
>> + 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);
>> }
>>
> thanks,
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
2022-11-22 8:47 ` Yang Yingliang
@ 2022-11-22 9:02 ` Heikki Krogerus
0 siblings, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2022-11-22 9:02 UTC (permalink / raw)
To: Yang Yingliang; +Cc: gregkh, chunfeng.yun, linux-usb
On Tue, Nov 22, 2022 at 04:47:00PM +0800, Yang Yingliang wrote:
>
> On 2022/11/22 16:33, Heikki Krogerus wrote:
> > Hi,
> >
> > On Mon, Nov 21, 2022 at 10:46:20PM +0800, Yang Yingliang wrote:
> > > I got the following report while doing device(mt6370-tcpc) load
> > > test with CONFIG_OF_UNITTEST and CONFIG_OF_DYNAMIC enabled:
> > >
> > > 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")
> > > Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > That's not the appropriate tag in this case. I have not suggested
> > this patch.
> >
> > > Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> > > ---
> > > v2 -> v3:
> > > Remove not needed null pointer check.
> > >
> > > v1 -> v2:
> > > Add description to how is the report generated.
> > > ---
> > > drivers/usb/roles/class.c | 5 ++++-
> > > 1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> > > index dfaed7eee94f..0650295f261c 100644
> > > --- a/drivers/usb/roles/class.c
> > > +++ b/drivers/usb/roles/class.c
> > > @@ -106,10 +106,13 @@ 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")) {
> > Please change that as well like I proposed earlier:
> >
> > if (!fwnode_property_present(parent, "usb-role-switch")) {
> >
> > You don't need to check the parent separately.
> Yes, fwnode_property_present() has already checked the parent, the parent
> check can be removed.
> Need I add your suggest tag when I send v4 to change it as above.
No. I still have not suggested this patch. I've only commented it.
thanks,
--
heikki
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-22 9:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-21 14:46 [PATCH v3] usb: roles: fix of node refcount leak in usb_role_switch_is_parent() Yang Yingliang
2022-11-22 8:33 ` Heikki Krogerus
2022-11-22 8:47 ` Yang Yingliang
2022-11-22 9:02 ` Heikki Krogerus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox