Skip to content

Commit 7a735a8

Browse files
Andrei Kuchynskigregkh
authored andcommitted
usb: typec: ucsi: Fix NULL pointer access
commit b13abcb7ddd8d38de769486db5bd917537b32ab1 upstream. Resources should be released only after all threads that utilize them have been destroyed. This commit ensures that resources are not released prematurely by waiting for the associated workqueue to complete before deallocating them. Cc: stable <[email protected]> Fixes: b9aa02c ("usb: typec: ucsi: Add polling mechanism for partner tasks like alt mode checking") Signed-off-by: Andrei Kuchynski <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 03fa71e commit 7a735a8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/usb/typec/ucsi/ucsi.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,11 +1313,11 @@ static int ucsi_init(struct ucsi *ucsi)
13131313

13141314
err_unregister:
13151315
for (con = connector; con->port; con++) {
1316+
if (con->wq)
1317+
destroy_workqueue(con->wq);
13161318
ucsi_unregister_partner(con);
13171319
ucsi_unregister_altmodes(con, UCSI_RECIPIENT_CON);
13181320
ucsi_unregister_port_psy(con);
1319-
if (con->wq)
1320-
destroy_workqueue(con->wq);
13211321
typec_unregister_port(con->port);
13221322
con->port = NULL;
13231323
}
@@ -1479,10 +1479,6 @@ void ucsi_unregister(struct ucsi *ucsi)
14791479

14801480
for (i = 0; i < ucsi->cap.num_connectors; i++) {
14811481
cancel_work_sync(&ucsi->connector[i].work);
1482-
ucsi_unregister_partner(&ucsi->connector[i]);
1483-
ucsi_unregister_altmodes(&ucsi->connector[i],
1484-
UCSI_RECIPIENT_CON);
1485-
ucsi_unregister_port_psy(&ucsi->connector[i]);
14861482

14871483
if (ucsi->connector[i].wq) {
14881484
struct ucsi_work *uwork;
@@ -1497,6 +1493,11 @@ void ucsi_unregister(struct ucsi *ucsi)
14971493
mutex_unlock(&ucsi->connector[i].lock);
14981494
destroy_workqueue(ucsi->connector[i].wq);
14991495
}
1496+
1497+
ucsi_unregister_partner(&ucsi->connector[i]);
1498+
ucsi_unregister_altmodes(&ucsi->connector[i],
1499+
UCSI_RECIPIENT_CON);
1500+
ucsi_unregister_port_psy(&ucsi->connector[i]);
15001501
typec_unregister_port(ucsi->connector[i].port);
15011502
}
15021503

0 commit comments

Comments
 (0)