Skip to content

Commit f87fb98

Browse files
jwrdegoedegregkh
authored andcommitted
usb: ucsi: Fix NULL pointer deref in ucsi_connector_change()
When ucsi_init() fails, ucsi->connector is NULL, yet in case of ucsi_acpi we may still get events which cause the ucs_acpi code to call ucsi_connector_change(), which then derefs the NULL ucsi->connector pointer. Fix this by not setting ucsi->ntfy inside ucsi_init() until ucsi_init() has succeeded, so that ucsi_connector_change() ignores the events because UCSI_ENABLE_NTFY_CONNECTOR_CHANGE is not set in the ntfy mask. Fixes: bdc62f2 ("usb: typec: ucsi: Simplified registration and I/O API") Link: https://bugzilla.kernel.org/show_bug.cgi?id=217106 Cc: [email protected] Reviewed-by: Heikki Krogerus <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fe15c26 commit f87fb98

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/usb/typec/ucsi/ucsi.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ static int ucsi_register_port(struct ucsi *ucsi, int index)
13291329
static int ucsi_init(struct ucsi *ucsi)
13301330
{
13311331
struct ucsi_connector *con;
1332-
u64 command;
1332+
u64 command, ntfy;
13331333
int ret;
13341334
int i;
13351335

@@ -1341,8 +1341,8 @@ static int ucsi_init(struct ucsi *ucsi)
13411341
}
13421342

13431343
/* Enable basic notifications */
1344-
ucsi->ntfy = UCSI_ENABLE_NTFY_CMD_COMPLETE | UCSI_ENABLE_NTFY_ERROR;
1345-
command = UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy;
1344+
ntfy = UCSI_ENABLE_NTFY_CMD_COMPLETE | UCSI_ENABLE_NTFY_ERROR;
1345+
command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;
13461346
ret = ucsi_send_command(ucsi, command, NULL, 0);
13471347
if (ret < 0)
13481348
goto err_reset;
@@ -1374,12 +1374,13 @@ static int ucsi_init(struct ucsi *ucsi)
13741374
}
13751375

13761376
/* Enable all notifications */
1377-
ucsi->ntfy = UCSI_ENABLE_NTFY_ALL;
1378-
command = UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy;
1377+
ntfy = UCSI_ENABLE_NTFY_ALL;
1378+
command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;
13791379
ret = ucsi_send_command(ucsi, command, NULL, 0);
13801380
if (ret < 0)
13811381
goto err_unregister;
13821382

1383+
ucsi->ntfy = ntfy;
13831384
return 0;
13841385

13851386
err_unregister:

0 commit comments

Comments
 (0)