The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] usb: typec: ucsi: Correct teardown ordering in ucsi_init() error path
@ 2026-07-17 10:46 Andrei Kuchynski
  2026-07-17 11:57 ` Borah, Chaitanya Kumar
  0 siblings, 1 reply; 2+ messages in thread
From: Andrei Kuchynski @ 2026-07-17 10:46 UTC (permalink / raw)
  To: Heikki Krogerus, Jameson Thies, Benson Leung, linux-usb,
	linux-kernel
  Cc: Greg Kroah-Hartman, Pooja Katiyar, Abhishek Pandit-Subedi,
	Johan Hovold, Hsin-Te Yuan, Myrrh Periwinkle, Jack Pham,
	Borah, Chaitanya Kumar, Sergey Senozhatsky, Andrei Kuchynski,
	stable

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")
Reported-by: "Borah, Chaitanya Kumar" <chaitanya.kumar.borah@intel.com>
Closes: https://lore.kernel.org/all/22064276-6c56-411a-9f20-6917ceeb865f@intel.com/
Signed-off-by: Andrei Kuchynski <akuchynski@chromium.org>
---
Changes in v2:
- Added Reported-by tag.

 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] usb: typec: ucsi: Correct teardown ordering in ucsi_init() error path
  2026-07-17 10:46 [PATCH v2] usb: typec: ucsi: Correct teardown ordering in ucsi_init() error path Andrei Kuchynski
@ 2026-07-17 11:57 ` Borah, Chaitanya Kumar
  0 siblings, 0 replies; 2+ messages in thread
From: Borah, Chaitanya Kumar @ 2026-07-17 11:57 UTC (permalink / raw)
  To: Andrei Kuchynski, Heikki Krogerus, Jameson Thies, Benson Leung,
	linux-usb, linux-kernel
  Cc: Greg Kroah-Hartman, Pooja Katiyar, Abhishek Pandit-Subedi,
	Johan Hovold, Hsin-Te Yuan, Myrrh Periwinkle, Jack Pham,
	Sergey Senozhatsky, stable



On 7/17/2026 4:16 PM, 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.
> 

Feel free to use.

Tested-by: Chaitanya Kumar Borah <chaitanya.kumar.borah@intel.com>


> Cc: stable@vger.kernel.org
> Fixes: 7aa7d4bf9d3f ("usb: typec: ucsi: Fix race condition and ordering in port unregistration")
> Reported-by: "Borah, Chaitanya Kumar" <chaitanya.kumar.borah@intel.com>
> Closes: https://lore.kernel.org/all/22064276-6c56-411a-9f20-6917ceeb865f@intel.com/
> Signed-off-by: Andrei Kuchynski <akuchynski@chromium.org>
> ---
> Changes in v2:
> - Added Reported-by tag.
> 
>   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));


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-17 11:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-17 10:46 [PATCH v2] usb: typec: ucsi: Correct teardown ordering in ucsi_init() error path Andrei Kuchynski
2026-07-17 11:57 ` Borah, Chaitanya Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox