* [PATCH] usb: typec: ucsi: Fix missing typec_unregister_port on error paths
@ 2025-11-24 12:20 Haotian Zhang
2025-11-24 12:29 ` Greg Kroah-Hartman
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Haotian Zhang @ 2025-11-24 12:20 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman
Cc: Dmitry Baryshkov, linux-usb, linux-kernel, Haotian Zhang
The ucsi_register_port() registers a Type-C port with
typec_register_port(), but several error paths after a successful
registration returned directly to cleanup without calling
typec_unregister_port(). This lead to a potential resource leak.
Add a common error-unwind path that calls typec_unregister_port()
for all failures to ensure proper cleanup.
Fixes: c1b0bc2dabfa ("usb: typec: Add support for UCSI interface")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
drivers/usb/typec/ucsi/ucsi.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 3f568f790f39..096c4911e8bf 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1656,14 +1656,14 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
if (ret) {
dev_err(ucsi->dev, "con%d: failed to register alt modes\n",
con->num);
- goto out;
+ goto out_unregister;
}
/* Get the status */
ret = ucsi_get_connector_status(con, false);
if (ret) {
dev_err(ucsi->dev, "con%d: failed to get status\n", con->num);
- goto out;
+ goto out_unregister;
}
if (ucsi->ops->connector_status)
@@ -1717,6 +1717,10 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
trace_ucsi_register_port(con->num, con);
+ goto out;
+
+out_unregister:
+ typec_unregister_port(con->port);
out:
fwnode_handle_put(cap->fwnode);
out_unlock:
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] usb: typec: ucsi: Fix missing typec_unregister_port on error paths 2025-11-24 12:20 [PATCH] usb: typec: ucsi: Fix missing typec_unregister_port on error paths Haotian Zhang @ 2025-11-24 12:29 ` Greg Kroah-Hartman 2025-11-25 8:27 ` Heikki Krogerus 2025-11-25 9:20 ` [PATCH v2] usb: typec: ucsi: Treat alt mode and status failures as non-fatal Haotian Zhang 2 siblings, 0 replies; 5+ messages in thread From: Greg Kroah-Hartman @ 2025-11-24 12:29 UTC (permalink / raw) To: Haotian Zhang; +Cc: Heikki Krogerus, Dmitry Baryshkov, linux-usb, linux-kernel On Mon, Nov 24, 2025 at 08:20:30PM +0800, Haotian Zhang wrote: > The ucsi_register_port() registers a Type-C port with > typec_register_port(), but several error paths after a successful > registration returned directly to cleanup without calling > typec_unregister_port(). This lead to a potential resource leak. > > Add a common error-unwind path that calls typec_unregister_port() > for all failures to ensure proper cleanup. > > Fixes: c1b0bc2dabfa ("usb: typec: Add support for UCSI interface") > Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn> How was this found? How was this tested? thanks, greg k-h ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] usb: typec: ucsi: Fix missing typec_unregister_port on error paths 2025-11-24 12:20 [PATCH] usb: typec: ucsi: Fix missing typec_unregister_port on error paths Haotian Zhang 2025-11-24 12:29 ` Greg Kroah-Hartman @ 2025-11-25 8:27 ` Heikki Krogerus 2025-11-25 9:20 ` [PATCH v2] usb: typec: ucsi: Treat alt mode and status failures as non-fatal Haotian Zhang 2 siblings, 0 replies; 5+ messages in thread From: Heikki Krogerus @ 2025-11-25 8:27 UTC (permalink / raw) To: Haotian Zhang Cc: Greg Kroah-Hartman, Dmitry Baryshkov, linux-usb, linux-kernel Mon, Nov 24, 2025 at 08:20:30PM +0800, Haotian Zhang kirjoitti: > The ucsi_register_port() registers a Type-C port with > typec_register_port(), but several error paths after a successful > registration returned directly to cleanup without calling > typec_unregister_port(). This lead to a potential resource leak. > > Add a common error-unwind path that calls typec_unregister_port() > for all failures to ensure proper cleanup. > > Fixes: c1b0bc2dabfa ("usb: typec: Add support for UCSI interface") > Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn> > --- > drivers/usb/typec/ucsi/ucsi.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c > index 3f568f790f39..096c4911e8bf 100644 > --- a/drivers/usb/typec/ucsi/ucsi.c > +++ b/drivers/usb/typec/ucsi/ucsi.c > @@ -1656,14 +1656,14 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con) > if (ret) { > dev_err(ucsi->dev, "con%d: failed to register alt modes\n", > con->num); > - goto out; > + goto out_unregister; > } > > /* Get the status */ > ret = ucsi_get_connector_status(con, false); > if (ret) { > dev_err(ucsi->dev, "con%d: failed to get status\n", con->num); > - goto out; > + goto out_unregister; > } > > if (ucsi->ops->connector_status) > @@ -1717,6 +1717,10 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con) > > trace_ucsi_register_port(con->num, con); > > + goto out; > + > +out_unregister: > + typec_unregister_port(con->port); No. We don't destroy the port if status or alt modes fail. The alt modes can't be considered critical because the firmware quite often claims alt modes are supported even though they are not. That should be explained, if not in documentation, then at least in the commit messages. Try something like this instead. diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index ec6c8f928dda..8de8935320be 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -1682,6 +1682,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con) if (ret) { dev_err(ucsi->dev, "con%d: failed to register alt modes\n", con->num); + ret = 0; goto out; } @@ -1689,6 +1690,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con) ret = ucsi_get_connector_status(con, false); if (ret) { dev_err(ucsi->dev, "con%d: failed to get status\n", con->num); + ret = 0; goto out; } And the commit you want to fix is b9aa02ca39a4 ("usb: typec: ucsi: Add polling mechanism for partner tasks like alt mode checking"). thanks, -- heikki ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2] usb: typec: ucsi: Treat alt mode and status failures as non-fatal 2025-11-24 12:20 [PATCH] usb: typec: ucsi: Fix missing typec_unregister_port on error paths Haotian Zhang 2025-11-24 12:29 ` Greg Kroah-Hartman 2025-11-25 8:27 ` Heikki Krogerus @ 2025-11-25 9:20 ` Haotian Zhang 2025-11-25 11:45 ` Greg Kroah-Hartman 2 siblings, 1 reply; 5+ messages in thread From: Haotian Zhang @ 2025-11-25 9:20 UTC (permalink / raw) To: Heikki Krogerus, Greg Kroah-Hartman Cc: Dmitry Baryshkov, linux-usb, linux-kernel, Haotian Zhang The ucsi_register_altmodes() and ucsi_get_connector_status() can fail for reasons that should not prevent the port from being registered. These failures should be logged but should not cause the entire port registration to fail. Set ret to 0 in these error paths to allow registration to continue. Fixes: b9aa02ca39a4 ("usb: typec: ucsi: Add polling mechanism for partner tasks like alt mode checking") Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn> --- Changes in v2: - Instead of unregistering the port on alt mode/status failures, treat these errors as non-fatal by setting ret = 0 - Changed Fixes tag to b9aa02ca39a4. --- drivers/usb/typec/ucsi/ucsi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 3f568f790f39..77b05cd3917e 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -1656,6 +1656,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con) if (ret) { dev_err(ucsi->dev, "con%d: failed to register alt modes\n", con->num); + ret = 0; goto out; } @@ -1663,6 +1664,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con) ret = ucsi_get_connector_status(con, false); if (ret) { dev_err(ucsi->dev, "con%d: failed to get status\n", con->num); + ret = 0; goto out; } -- 2.25.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] usb: typec: ucsi: Treat alt mode and status failures as non-fatal 2025-11-25 9:20 ` [PATCH v2] usb: typec: ucsi: Treat alt mode and status failures as non-fatal Haotian Zhang @ 2025-11-25 11:45 ` Greg Kroah-Hartman 0 siblings, 0 replies; 5+ messages in thread From: Greg Kroah-Hartman @ 2025-11-25 11:45 UTC (permalink / raw) To: Haotian Zhang; +Cc: Heikki Krogerus, Dmitry Baryshkov, linux-usb, linux-kernel On Tue, Nov 25, 2025 at 05:20:39PM +0800, Haotian Zhang wrote: > The ucsi_register_altmodes() and ucsi_get_connector_status() can fail > for reasons that should not prevent the port from being registered. > These failures should be logged but should not cause the entire port > registration to fail. > > Set ret to 0 in these error paths to allow registration to continue. > > Fixes: b9aa02ca39a4 ("usb: typec: ucsi: Add polling mechanism for partner tasks like alt mode checking") > Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> > Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn> > --- > Changes in v2: > - Instead of unregistering the port on alt mode/status failures, > treat these errors as non-fatal by setting ret = 0 > - Changed Fixes tag to b9aa02ca39a4. > --- > drivers/usb/typec/ucsi/ucsi.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c > index 3f568f790f39..77b05cd3917e 100644 > --- a/drivers/usb/typec/ucsi/ucsi.c > +++ b/drivers/usb/typec/ucsi/ucsi.c > @@ -1656,6 +1656,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con) > if (ret) { > dev_err(ucsi->dev, "con%d: failed to register alt modes\n", > con->num); > + ret = 0; > goto out; > } > > @@ -1663,6 +1664,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con) > ret = ucsi_get_connector_status(con, false); > if (ret) { > dev_err(ucsi->dev, "con%d: failed to get status\n", con->num); > + ret = 0; > goto out; > } > > -- > 2.25.1 > > Hi, This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree. You are receiving this message because of the following common error(s) as indicated below: - You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this. If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers. thanks, greg k-h's patch email bot ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-25 11:45 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-11-24 12:20 [PATCH] usb: typec: ucsi: Fix missing typec_unregister_port on error paths Haotian Zhang 2025-11-24 12:29 ` Greg Kroah-Hartman 2025-11-25 8:27 ` Heikki Krogerus 2025-11-25 9:20 ` [PATCH v2] usb: typec: ucsi: Treat alt mode and status failures as non-fatal Haotian Zhang 2025-11-25 11:45 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).