[PATCH] usb: typec: ucsi: Correct teardown ordering in ucsi_init() error path

Andrei Kuchynski posted 1 patch 1 week ago
There is a newer version of this series
drivers/usb/typec/ucsi/ucsi.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] usb: typec: ucsi: Correct teardown ordering in ucsi_init() error path
Posted by Andrei Kuchynski 1 week ago
The commit 7aa7d4bf9d3f ("usb: typec: ucsi: Fix race condition and
ordering in port unregistration") consolidated port teardown into the
ucsi_unregister_port() helper. However, it introduced an ordering problem
in the ucsi_init() error path.

Fix this by ensuring ucsi_unregister_port() is called before we unregister
their corresponding lockdep keys.

Cc: stable@vger.kernel.org
Fixes: 7aa7d4bf9d3f ("usb: typec: ucsi: Fix race condition and ordering in port unregistration")
Link: https://lore.kernel.org/all/22064276-6c56-411a-9f20-6917ceeb865f@intel.com/
Signed-off-by: Andrei Kuchynski <akuchynski@chromium.org>
---
 drivers/usb/typec/ucsi/ucsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 1ae4224d2dfc3..49f1c53721bbd 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -2142,11 +2142,11 @@ static int ucsi_init(struct ucsi *ucsi)
 	return 0;
 
 err_unregister:
+	for (con = connector; con->port; con++)
+		ucsi_unregister_port(con);
 	for (i = 0; i < ucsi->cap.num_connectors; i++)
 		lockdep_unregister_key(&connector[i].lock_key);
 
-	for (con = connector; con->port; con++)
-		ucsi_unregister_port(con);
 	kfree(connector);
 err_reset:
 	memset(&ucsi->cap, 0, sizeof(ucsi->cap));
-- 
2.55.0.229.g6434b31f56-goog
Re: [PATCH] usb: typec: ucsi: Correct teardown ordering in ucsi_init() error path
Posted by Greg Kroah-Hartman 1 week ago
On Fri, Jul 17, 2026 at 09:50:06AM +0000, Andrei Kuchynski wrote:
> The commit 7aa7d4bf9d3f ("usb: typec: ucsi: Fix race condition and
> ordering in port unregistration") consolidated port teardown into the
> ucsi_unregister_port() helper. However, it introduced an ordering problem
> in the ucsi_init() error path.
> 
> Fix this by ensuring ucsi_unregister_port() is called before we unregister
> their corresponding lockdep keys.
> 
> Cc: stable@vger.kernel.org
> Fixes: 7aa7d4bf9d3f ("usb: typec: ucsi: Fix race condition and ordering in port unregistration")
> Link: https://lore.kernel.org/all/22064276-6c56-411a-9f20-6917ceeb865f@intel.com/
> Signed-off-by: Andrei Kuchynski <akuchynski@chromium.org>
> ---
>  drivers/usb/typec/ucsi/ucsi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

You forgot a reported-by: tag :(