Skip to contentSkip to conversation

usb: roles: fix of node refcount leak in usb_role_switch_is_parent()

PATCH Superseded Yang Yingliang 2 participants 4 messages Nov 21, 2022 – Nov 22, 2022 USB

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 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.

Fixes 6fadd72943b8 ("usb: roles: get usb-role-switch from parent")

---
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(-)
drivers/usb/roles/class.c +4 -1
index dfaed7eee94f..0650295f261c 100644
@@ -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);
 }
 
Signature · 1 line
2.25.1
#1 lore raw

Hi,

Quoted 7 lines · Yang Yingliang

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

Quoted 5 lines

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")

That's not the appropriate tag in this case. I have not suggested this patch.

Quoted 16 lines

---
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(-)
drivers/usb/roles/class.c +0 -0
index dfaed7eee94f..0650295f261c 100644

drivers/usb/roles/class.c usb_role_switch_is_parent(struct fwnode_handle *fwnode) · line 109

Quoted 5 lines
drivers/usb/roles/class.c +1 -1
@@ -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.

drivers/usb/roles/class.c usb_role_switch_is_parent(struct fwnode_handle *fwnode) · line 118

Quoted 9 lines
drivers/usb/roles/class.c +3 -0
+		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,

Signature · 1 line
heikki
#2 lore raw
Quoted 37 lines · Heikki Krogerus

Hi,

Quoted 7 lines · Yang Yingliang

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

Quoted 5 lines

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")

That's not the appropriate tag in this case. I have not suggested this patch.

Quoted 19 lines

---
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(-)
drivers/usb/roles/class.c +0 -0
index dfaed7eee94f..0650295f261c 100644
@@ -106,10 +106,13 @@ usb_role_switch_is_parent(struct fwnode_handle *fwnode)
  	struct fwnode_handle *parent = fwnode_get_parent(fwnode);
  	struct device *dev;
 
Quoted 7 lines

drivers/usb/roles/class.c usb_role_switch_is_parent(struct fwnode_handle *fwnode) · line 109

Quoted 2 lines
drivers/usb/roles/class.c +1 -1
-	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

Quoted 12 lines

drivers/usb/roles/class.c usb_role_switch_is_parent(struct fwnode_handle *fwnode) · line 118

Quoted 10 lines
drivers/usb/roles/class.c +3 -0
+		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,

#3 lore raw
Quoted 42 lines · Yang Yingliang
Quoted 40 lines · Heikki Krogerus

Hi,

Quoted 7 lines · Yang Yingliang

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

Quoted 5 lines

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")

That's not the appropriate tag in this case. I have not suggested this patch.

Quoted 16 lines

---
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(-)
drivers/usb/roles/class.c +0 -0
index dfaed7eee94f..0650295f261c 100644

drivers/usb/roles/class.c usb_role_switch_is_parent(struct fwnode_handle *fwnode) · line 108

Quoted 4 lines
drivers/usb/roles/class.c +1 -1
@@ -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:

Quoted 6 lines
Quoted 3 lines
	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,

Signature · 1 line
heikki