* [PATCH] extcon: ptn5150: fix fwnode reference leak in ptn5150_i2c_probe()
@ 2026-09-06 19:49 Miles Krause
2026-09-07 2:58 ` Xu Yang
2026-11-27 23:14 ` Chanwoo Choi
0 siblings, 2 replies; 3+ messages in thread
From: Miles Krause @ 2026-09-06 19:49 UTC (permalink / raw)
To: Krzysztof Kozlowski, MyungJoo Ham, Chanwoo Choi, Xu Yang, Frank Li
Cc: linux-kernel, Miles Krause
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.
Fixes: 842546c56345 ("extcon: ptn5150: Add Type-C orientation switch support")
Signed-off-by: Miles Krause <mileskrause5200@gmail.com>
---
drivers/extcon/extcon-ptn5150.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c
index eca1b140aeb0..ede38eec2466 100644
--- a/drivers/extcon/extcon-ptn5150.c
+++ b/drivers/extcon/extcon-ptn5150.c
@@ -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,
--
Miles Krause <mileskrause5200@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] extcon: ptn5150: fix fwnode reference leak in ptn5150_i2c_probe()
2026-09-06 19:49 [PATCH] extcon: ptn5150: fix fwnode reference leak in ptn5150_i2c_probe() Miles Krause
@ 2026-09-07 2:58 ` Xu Yang
2026-11-27 23:14 ` Chanwoo Choi
1 sibling, 0 replies; 3+ messages in thread
From: Xu Yang @ 2026-09-07 2:58 UTC (permalink / raw)
To: Miles Krause
Cc: Krzysztof Kozlowski, MyungJoo Ham, Chanwoo Choi, Xu Yang,
Frank Li, linux-kernel
On Sun, Sep 06, 2026 at 03:49:24PM -0400, Miles Krause wrote:
> 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.
>
> Fixes: 842546c56345 ("extcon: ptn5150: Add Type-C orientation switch support")
> Signed-off-by: Miles Krause <mileskrause5200@gmail.com>
Reviewed-by: Xu Yang <xu.yang_2@nxp.com>
> ---
> drivers/extcon/extcon-ptn5150.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c
> index eca1b140aeb0..ede38eec2466 100644
> --- a/drivers/extcon/extcon-ptn5150.c
> +++ b/drivers/extcon/extcon-ptn5150.c
> @@ -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,
> --
> Miles Krause <mileskrause5200@gmail.com>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] extcon: ptn5150: fix fwnode reference leak in ptn5150_i2c_probe()
2026-09-06 19:49 [PATCH] extcon: ptn5150: fix fwnode reference leak in ptn5150_i2c_probe() Miles Krause
2026-09-07 2:58 ` Xu Yang
@ 2026-11-27 23:14 ` Chanwoo Choi
1 sibling, 0 replies; 3+ messages in thread
From: Chanwoo Choi @ 2026-11-27 23:14 UTC (permalink / raw)
To: Miles Krause, Krzysztof Kozlowski, MyungJoo Ham, Chanwoo Choi,
Xu Yang, Frank Li
Cc: linux-kernel
On 9/7/2026 4:49 AM, Miles Krause wrote:
> 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.
>
> Fixes: 842546c56345 ("extcon: ptn5150: Add Type-C orientation switch support")
> Signed-off-by: Miles Krause <mileskrause5200@gmail.com>
> ---
> drivers/extcon/extcon-ptn5150.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c
> index eca1b140aeb0..ede38eec2466 100644
> --- a/drivers/extcon/extcon-ptn5150.c
> +++ b/drivers/extcon/extcon-ptn5150.c
> @@ -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,
Applied it. Thanks.
--
Best Regards,
Chanwoo Choi
Principal Engineer, Samsung Electronics
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-27 23:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-06 19:49 [PATCH] extcon: ptn5150: fix fwnode reference leak in ptn5150_i2c_probe() Miles Krause
2026-09-07 2:58 ` Xu Yang
2026-11-27 23:14 ` Chanwoo Choi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®