From: Haotian Zhang <vulab@iscas.ac.cn>
To: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Haotian Zhang <vulab@iscas.ac.cn>
Subject: [PATCH] usb: typec: ucsi: Fix missing typec_unregister_port on error paths
Date: Mon, 24 Nov 2025 20:20:30 +0800 [thread overview]
Message-ID: <20251124122030.1759-1-vulab@iscas.ac.cn> (raw)
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
next reply other threads:[~2025-11-24 12:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-24 12:20 Haotian Zhang [this message]
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
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=20251124122030.1759-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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
all inboxes | Powered by JetHome®