extcon: ptn5150: fix fwnode reference leak in ptn5150_i2c_probe()
PATCH 1/1 extcon: ptn5150: fix fwnode reference leak in ptn5150_i2c_probe()
ptn5150_i2c_probe() looks up the "connector" child node with device_get_named_child_node(), but never releases the reference that the lookup returns.
fwnode_typec_switch_get() and fwnode_usb_role_switch_get() each take their own reference on the switch they hand back, so the caller still owns the fwnode reference. Nothing in the driver drops it: the devm cleanup handler ptn5150_work_sync_and_put() releases info->role_sw and info->orient_sw only. The node is therefore leaked on both error returns that follow the lookup, and on a fully successful probe.
Declare 'connector' with __free(fwnode_handle) so that the reference is released on every path out of the function.
--- drivers/extcon/extcon-ptn5150.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/extcon/extcon-ptn5150.c +2 -2
@@ -256,7 +256,6 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c) {struct device *dev = &i2c->dev;struct device_node *np = i2c->dev.of_node; -struct fwnode_handle *connector;struct ptn5150_info *info;int ret;
@@ -343,7 +342,8 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)if (ret)return -EINVAL ; - connector =device_get_named_child_node (dev,"connector" ); + struct fwnode_handle *connector __free(fwnode_handle) = +device_get_named_child_node (dev,"connector" );if (connector) { info->orient_sw =fwnode_typec_switch_get (connector);if (IS_ERR (info->orient_sw))
---
base-commit: 88405f0ad1d5c680afe3ea0ce9345fa9e1deaac8
change-id: 20260906-extcon-ptn5150-fwnode-leak-81c395149a9d
Best regards,
Signature · 1 line
Miles Krause <[email protected]>
Quoted 11 lines · Miles Krause
ptn5150_i2c_probe()looks up the "connector" child node withdevice_get_named_child_node(), but never releases the reference that the lookup returns.
fwnode_typec_switch_get()andfwnode_usb_role_switch_get()each take their own reference on the switch they hand back, so the caller still owns the fwnode reference. Nothing in the driver drops it: the devm cleanup handlerptn5150_work_sync_and_put()releasesinfo->role_swandinfo->orient_swonly. The node is therefore leaked on both error returns that follow the lookup, and on a fully successful probe.
Quoted 5 lines
Declare 'connector' with
__free(fwnode_handle)so that the reference is released on every path out of the function.Fixes 842546c56345 ("extcon: ptn5150: Add Type-C orientation switch support")Signed-off-by Miles Krause <[email protected]>
Quoted 35 lines
--- drivers/extcon/extcon-ptn5150.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/extcon/extcon-ptn5150.c +2
-3@@ -256,7 +256,6 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c) {struct device *dev = &i2c->dev;struct device_node *np = i2c->dev.of_node; -struct fwnode_handle *connector;struct ptn5150_info *info;int ret;@@ -343,7 +342,8 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)if (ret)return -EINVAL ; - connector =device_get_named_child_node (dev,"connector" ); + struct fwnode_handle *connector __free(fwnode_handle) = +device_get_named_child_node (dev,"connector" );if (connector) { info->orient_sw =fwnode_typec_switch_get (connector);if (IS_ERR (info->orient_sw)) ---base-commit:
88405f0ad1d5c680afe3ea0ce9345fa9e1deaac8
change-id: 20260906-extcon-ptn5150-fwnode-leak-81c395149a9dBest regards,
Signature · 1 line
Miles Krause <[email protected]>
Chanwoo Choi
AppliedQuoted 47 lines · Miles Krause
ptn5150_i2c_probe()looks up the "connector" child node withdevice_get_named_child_node(), but never releases the reference that the lookup returns.
fwnode_typec_switch_get()andfwnode_usb_role_switch_get()each take their own reference on the switch they hand back, so the caller still owns the fwnode reference. Nothing in the driver drops it: the devm cleanup handlerptn5150_work_sync_and_put()releasesinfo->role_swandinfo->orient_swonly. The node is therefore leaked on both error returns that follow the lookup, and on a fully successful probe.Declare 'connector' with
__free(fwnode_handle)so that the reference is released on every path out of the function.Fixes 842546c56345 ("extcon: ptn5150: Add Type-C orientation switch support")Signed-off-by Miles Krause <[email protected]>--- drivers/extcon/extcon-ptn5150.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/extcon/extcon-ptn5150.c +2
-3@@ -256,7 +256,6 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c) {struct device *dev = &i2c->dev;struct device_node *np = i2c->dev.of_node; -struct fwnode_handle *connector;struct ptn5150_info *info;int ret;@@ -343,7 +342,8 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)if (ret)return -EINVAL ; - connector =device_get_named_child_node (dev,"connector" ); + struct fwnode_handle *connector __free(fwnode_handle) = +device_get_named_child_node (dev,"connector" );if (connector) { info->orient_sw =fwnode_typec_switch_get (connector);if (IS_ERR (info->orient_sw)) ---base-commit:
88405f0ad1d5c680afe3ea0ce9345fa9e1deaac8
change-id: 20260906-extcon-ptn5150-fwnode-leak-81c395149a9d
Quoted 1 line
Best regards,
Applied it. Thanks.
Signature · 3 lines
Best Regards, Chanwoo Choi Principal Engineer, Samsung Electronics