From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Haotian Zhang <vulab@iscas.ac.cn>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: typec: ucsi: Fix missing typec_unregister_port on error paths
Date: Tue, 25 Nov 2025 10:27:13 +0200 [thread overview]
Message-ID: <aSVoYbBqC_h3mqcA@kuha> (raw)
In-Reply-To: <20251124122030.1759-1-vulab@iscas.ac.cn>
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
next prev parent reply other threads:[~2025-11-25 8:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aSVoYbBqC_h3mqcA@kuha \
--to=heikki.krogerus@linux.intel.com \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=vulab@iscas.ac.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).