linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [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

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).