* [PATCH v2] usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
@ 2022-11-19 9:15 Yang Yingliang
2022-11-21 7:49 ` Chunfeng Yun (云春峰)
2022-11-21 7:55 ` Chunfeng Yun (云春峰)
0 siblings, 2 replies; 6+ messages in thread
From: Yang Yingliang @ 2022-11-19 9:15 UTC (permalink / raw)
To: gregkh, chunfeng.yun; +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")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
v1 -> v2:
Add description to how is the report generated.
---
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] 6+ messages in thread
* Re: [PATCH v2] usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
2022-11-19 9:15 [PATCH v2] usb: roles: fix of node refcount leak in usb_role_switch_is_parent() Yang Yingliang
@ 2022-11-21 7:49 ` Chunfeng Yun (云春峰)
2022-11-21 8:55 ` Heikki Krogerus
2022-11-21 7:55 ` Chunfeng Yun (云春峰)
1 sibling, 1 reply; 6+ messages in thread
From: Chunfeng Yun (云春峰) @ 2022-11-21 7:49 UTC (permalink / raw)
To: yangyingliang@huawei.com, gregkh@linuxfoundation.org,
heikki.krogerus@linux.intel.com
Cc: linux-usb@vger.kernel.org
On Sat, 2022-11-19 at 17:15 +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")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> v1 -> v2:
> Add description to how is the report generated.
> ---
> 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);
> }
>
+ Heikki
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
2022-11-19 9:15 [PATCH v2] usb: roles: fix of node refcount leak in usb_role_switch_is_parent() Yang Yingliang
2022-11-21 7:49 ` Chunfeng Yun (云春峰)
@ 2022-11-21 7:55 ` Chunfeng Yun (云春峰)
2022-11-21 8:28 ` Yang Yingliang
1 sibling, 1 reply; 6+ messages in thread
From: Chunfeng Yun (云春峰) @ 2022-11-21 7:55 UTC (permalink / raw)
To: yangyingliang@huawei.com, gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org
Hi Yingliang,
On Sat, 2022-11-19 at 17:15 +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")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> v1 -> v2:
> Add description to how is the report generated.
> ---
> 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);
> }
Please use get_maintainer script to find who you should sent to after
generating patches
e.g.:
./scripts/get_maintainer.pl --no-rolestats 00* | gawk '{printf("
--cc=\"%s\" ", $0)} END{printf("\n")}'
Thanks
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
2022-11-21 7:55 ` Chunfeng Yun (云春峰)
@ 2022-11-21 8:28 ` Yang Yingliang
0 siblings, 0 replies; 6+ messages in thread
From: Yang Yingliang @ 2022-11-21 8:28 UTC (permalink / raw)
To: Chunfeng Yun (云春峰),
gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, yangyingliang
On 2022/11/21 15:55, Chunfeng Yun (云春峰) wrote:
> Hi Yingliang,
>
> On Sat, 2022-11-19 at 17:15 +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")
>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>> ---
>> v1 -> v2:
>> Add description to how is the report generated.
>> ---
>> 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);
>> }
> Please use get_maintainer script to find who you should sent to after
> generating patches
>
> e.g.:
> ./scripts/get_maintainer.pl --no-rolestats 00* | gawk '{printf("
> --cc=\"%s\" ", $0)} END{printf("\n")}'
>
> Thanks
I used get_maintainer.pl to get the maintainer in Linux 6.1-rc5 and sent
the patch.
./scripts/get_maintainer.pl
0001-usb-roles-fix-of-node-refcount-leak-in-usb_role_swit.patch
Greg Kroah-Hartman <gregkh@linuxfoundation.org> (supporter:USB
SUBSYSTEM,blamed_fixes:1/1=100%)
Chunfeng Yun <chunfeng.yun@mediatek.com> (blamed_fixes:1/1=100%)
linux-usb@vger.kernel.org (open list:USB SUBSYSTEM)
linux-kernel@vger.kernel.org (open list)
Thanks,
Yang
>
>>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
2022-11-21 7:49 ` Chunfeng Yun (云春峰)
@ 2022-11-21 8:55 ` Heikki Krogerus
2022-11-21 9:01 ` Yang Yingliang
0 siblings, 1 reply; 6+ messages in thread
From: Heikki Krogerus @ 2022-11-21 8:55 UTC (permalink / raw)
To: Chunfeng Yun (云春峰)
Cc: yangyingliang@huawei.com, gregkh@linuxfoundation.org,
linux-usb@vger.kernel.org
Hi,
On Mon, Nov 21, 2022 at 07:49:31AM +0000, Chunfeng Yun (云春峰) wrote:
> On Sat, 2022-11-19 at 17:15 +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")
> > Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> > ---
> > v1 -> v2:
> > Add description to how is the report generated.
> > ---
> > 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;
> > + }
fwnode API should be NULL safe, so perhaps like this - clean also the
old condition while at it:
if (!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);
> > }
> >
> + Heikki
Thanks Chunfeng!
cheers,
--
heikki
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
2022-11-21 8:55 ` Heikki Krogerus
@ 2022-11-21 9:01 ` Yang Yingliang
0 siblings, 0 replies; 6+ messages in thread
From: Yang Yingliang @ 2022-11-21 9:01 UTC (permalink / raw)
To: Heikki Krogerus, Chunfeng Yun (云春峰)
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
yangyingliang
Hi,
On 2022/11/21 16:55, Heikki Krogerus wrote:
> Hi,
>
> On Mon, Nov 21, 2022 at 07:49:31AM +0000, Chunfeng Yun (云春峰) wrote:
>> On Sat, 2022-11-19 at 17:15 +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")
>>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>>> ---
>>> v1 -> v2:
>>> Add description to how is the report generated.
>>> ---
>>> 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;
>>> + }
> fwnode API should be NULL safe, so perhaps like this - clean also the
> old condition while at it:
>
> if (!fwnode_property_present(parent, "usb-role-switch")) {
> fwnode_handle_put(parent);
> return NULL;
> }
Thanks for your suggestion, I will send a v3 to change this.
Thanks,
Yang
>
>>> dev = class_find_device_by_fwnode(role_class, parent);
>>> + fwnode_handle_put(parent);
>>> return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
>>> }
>>>
>> + Heikki
> Thanks Chunfeng!
>
> cheers,
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-11-21 9:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-19 9:15 [PATCH v2] usb: roles: fix of node refcount leak in usb_role_switch_is_parent() Yang Yingliang
2022-11-21 7:49 ` Chunfeng Yun (云春峰)
2022-11-21 8:55 ` Heikki Krogerus
2022-11-21 9:01 ` Yang Yingliang
2022-11-21 7:55 ` Chunfeng Yun (云春峰)
2022-11-21 8:28 ` Yang Yingliang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox