Skip to contentSkip to conversation

usb: typec: wusb3801: fix fwnode refcount leak in wusb3801_probe()

PATCH In review Yang Yingliang 2 participants 2 messages Dec 3, 2022 – Dec 7, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: typec: wusb3801: fix fwnode refcount leak in wusb3801_probe()

I got the following report while doing fault injection test:

OF: ERROR: memory leak, expected refcount 1 instead of 4, of_node_get()/of_node_put() unbalanced - destroy cset entry:
attach overlay node /i2c/tcpc@60/connector

If wusb3801_hw_init() fails, fwnode_handle_put() needs be called to avoid refcount leak.

Fixes d016cbe4d7ac ("usb: typec: Support the WUSB3801 port controller")
---
 drivers/usb/typec/wusb3801.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/typec/wusb3801.c +1 -1
index 3cc7a15ecbd3..a43a18d4b02e 100644
@@ -364,7 +364,7 @@ static int wusb3801_probe(struct i2c_client *client)
 	/* Initialize the hardware with the devicetree settings. */
 	ret = wusb3801_hw_init(wusb3801);
 	if (ret)
-		return ret;
+		goto err_put_connector;
 
 	wusb3801->cap.revision		= USB_TYPEC_REV_1_2;
 	wusb3801->cap.accessory[0]	= TYPEC_ACCESSORY_AUDIO;
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Yang Yingliang

I got the following report while doing fault injection test:

OF: ERROR: memory leak, expected refcount 1 instead of 4, of_node_get()/of_node_put() unbalanced - destroy cset entry:
attach overlay node /i2c/tcpc@60/connector

If wusb3801_hw_init() fails, fwnode_handle_put() needs be called to avoid refcount leak.

Fixes d016cbe4d7ac ("usb: typec: Support the WUSB3801 port controller")
Quoted 19 lines
---
 drivers/usb/typec/wusb3801.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/typec/wusb3801.c +1 -1
index 3cc7a15ecbd3..a43a18d4b02e 100644
@@ -364,7 +364,7 @@ static int wusb3801_probe(struct i2c_client *client)
 	/* Initialize the hardware with the devicetree settings. */
 	ret = wusb3801_hw_init(wusb3801);
 	if (ret)
-		return ret;
+		goto err_put_connector;
 
 	wusb3801->cap.revision		= USB_TYPEC_REV_1_2;
 	wusb3801->cap.accessory[0]	= TYPEC_ACCESSORY_AUDIO;
Signature · 1 line
2.25.1
Signature · 1 line
heikki