usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
PATCH v2 1/1 usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
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.
---
v1 -> v2:
Add description to how is the report generated.
--- drivers/usb/roles/class.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/roles/class.c +5 -1
@@ -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 ); }
Signature · 1 line
2.25.1
Quoted 40 lines · Yang Yingliang
I got the following report while doing device(mt6370-tcpc) load test with
CONFIG_OF_UNITTESTandCONFIG_OF_DYNAMICenabled: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@34The '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 <[email protected]>---
v1 -> v2:
Add description to how is the report generated.--- drivers/usb/roles/class.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/usb/roles/class.c +5
-1@@ -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);
Quoted 3 lines
return dev ?
to_role_switch(dev):ERR_PTR(-EPROBE_DEFER);
}
+ Heikki
Hi,
Quoted 30 lines · Chunfeng Yun (云春峰)
Quoted 29 lines · Yang Yingliang
I got the following report while doing device(mt6370-tcpc) load test with
CONFIG_OF_UNITTESTandCONFIG_OF_DYNAMICenabled: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@34The '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 <[email protected]>---
v1 -> v2:
Add description to how is the report generated.--- drivers/usb/roles/class.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/usb/roles/class.c +0
-0@@ -106,10 +106,14 @@ usb_role_switch_is_parent(struct fwnode_handle *fwnode)struct fwnode_handle *parent =fwnode_get_parent (fwnode);struct device *dev;
Quoted 8 lines
drivers/usb/roles/class.c usb_role_switch_is_parent(struct fwnode_handle *fwnode) · line 113
Quoted 8 lines
drivers/usb/roles/class.c +4
-1-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;
}Quoted 6 lines
Quoted 5 lines
drivers/usb/roles/class.c +1
-0dev =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,
Signature · 1 line
heikki
Hi,
Quoted 44 lines · Heikki Krogerus
Hi,
Quoted 30 lines · Chunfeng Yun (云春峰)
Quoted 29 lines · Yang Yingliang
I got the following report while doing device(mt6370-tcpc) load test with
CONFIG_OF_UNITTESTandCONFIG_OF_DYNAMICenabled: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@34The '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 <[email protected]>---
v1 -> v2:
Add description to how is the report generated.--- drivers/usb/roles/class.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/usb/roles/class.c +0
-0@@ -106,10 +106,14 @@ usb_role_switch_is_parent(struct fwnode_handle *fwnode)struct fwnode_handle *parent =fwnode_get_parent (fwnode);struct device *dev;Quoted 8 lines
drivers/usb/roles/class.c usb_role_switch_is_parent(struct fwnode_handle *fwnode) · line 113
Quoted 8 lines
drivers/usb/roles/class.c +4
-1-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:
Quoted 4 lines
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
Quoted 11 lines
Quoted 7 lines
Quoted 6 lines
drivers/usb/roles/class.c +1
-0dev =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,
Hi Yingliang,
Quoted 40 lines · Yang Yingliang
I got the following report while doing device(mt6370-tcpc) load test with
CONFIG_OF_UNITTESTandCONFIG_OF_DYNAMICenabled: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@34The '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 <[email protected]>---
v1 -> v2:
Add description to how is the report generated.--- drivers/usb/roles/class.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/usb/roles/class.c +5
-1@@ -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);
Quoted 2 lines
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
Quoted 1 line
Quoted 48 lines · Chunfeng Yun (云春峰)
Hi Yingliang,
Quoted 40 lines · Yang Yingliang
I got the following report while doing device(mt6370-tcpc) load test with
CONFIG_OF_UNITTESTandCONFIG_OF_DYNAMICenabled: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@34The '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 <[email protected]>---
v1 -> v2:
Add description to how is the report generated.--- drivers/usb/roles/class.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/usb/roles/class.c +5
-1@@ -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);Quoted 2 lines
return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); }Please use
get_maintainerscript to find who you should sent to after generating patches
Quoted 5 lines
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 <[email protected]> (supporter:USB SUBSYSTEM,blamed_fixes:1/1=100%) Chunfeng Yun <[email protected]> (blamed_fixes:1/1=100%) [email protected] (open list:USB SUBSYSTEM)
[email protected] (open list)
Thanks,
Yang
Quoted 2 lines
Quoted 2 lines