Skip to content

Commit 22d96a2

Browse files
jthiesatgooglegregkh
authored andcommitted
usb: typec: ucsi: Only set number of plug altmodes after registration
Move the setting of the plug's number of alternate modes into the same condition as the plug's registration to prevent dereferencing the connector's plug pointer while it is null. Fixes: c313a44 ("usb: typec: ucsi: Always set number of alternate modes") Suggested-by: Jon Hunter <[email protected]> Signed-off-by: Jameson Thies <[email protected]> Reviewed-by: Benson Leung <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Tested-by: Jon Hunter <[email protected]> Reviewed-by: Jon Hunter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 36b1235 commit 22d96a2

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/usb/typec/ucsi/ucsi.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,13 +1180,13 @@ static int ucsi_check_cable(struct ucsi_connector *con)
11801180
ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
11811181
if (ret < 0)
11821182
return ret;
1183-
}
11841183

1185-
if (con->plug_altmode[0]) {
1186-
num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
1187-
typec_plug_set_num_altmodes(con->plug, num_plug_am);
1188-
} else {
1189-
typec_plug_set_num_altmodes(con->plug, 0);
1184+
if (con->plug_altmode[0]) {
1185+
num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
1186+
typec_plug_set_num_altmodes(con->plug, num_plug_am);
1187+
} else {
1188+
typec_plug_set_num_altmodes(con->plug, 0);
1189+
}
11901190
}
11911191

11921192
return 0;

0 commit comments

Comments
 (0)