Skip to contentSkip to conversation

usb: typec: class: drop PD lookup reference

PATCH Superseded Shuangpeng Bai 2 participants 2 messages Jul 2 – Jul 3

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: typec: class: drop PD lookup reference

usb_power_delivery_find() wraps class_find_device_by_name(). That helper returns a device reference that must be released by the caller.

select_usb_power_delivery_store() only needs this reference while calling the pd_set callback. Drop it once the callback returns. Otherwise the sysfs write can pin the selected USB Power Delivery object and prevent it from being released on unregister.

Fixes a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners")
---
 drivers/usb/typec/class.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/typec/class.c +1 -0
index 0977581ad1b6..0595e8cb83aa 100644
@@ -1619,6 +1619,7 @@ static ssize_t select_usb_power_delivery_store(struct device *dev,
 		return -EINVAL;
 
 	ret = port->ops->pd_set(port, pd);
+	put_device(&pd->dev);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 10 lines · Shuangpeng Bai

usb_power_delivery_find() wraps class_find_device_by_name(). That helper returns a device reference that must be released by the caller.

select_usb_power_delivery_store() only needs this reference while calling the pd_set callback. Drop it once the callback returns. Otherwise the sysfs write can pin the selected USB Power Delivery object and prevent it from being released on unregister.

Fixes a7cff92f0635 ("usb: typec: USB Power Delivery helpers for ports and partners")

You need to Cc [email protected]

https://docs.kernel.org/process/5.Posting.html#sending-the-patch

thanks,

Quoted 18 lines
---
 drivers/usb/typec/class.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/typec/class.c +1 -0
index 0977581ad1b6..0595e8cb83aa 100644
@@ -1619,6 +1619,7 @@ static ssize_t select_usb_power_delivery_store(struct device *dev,
 		return -EINVAL;
 
 	ret = port->ops->pd_set(port, pd);
+	put_device(&pd->dev);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.43.0
Signature · 1 line
heikki