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: c313a44ac9cd ("usb: typec: ucsi: Always set number of alternate modes") Suggested-by: Jon Hunter <jonathanh@nvidia.com> Signed-off-by: Jameson Thies <jthies@google.com> Reviewed-by: Benson Leung <bleung@chromium.org> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Tested-by: Jon Hunter <jonathanh@nvidia.com> Reviewed-by: Jon Hunter <jonathanh@nvidia.com> Link: https://lore.kernel.org/r/20240625004607.3223757-1-jthies@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
36b1235a8a
commit
22d96a2854
@ -1180,13 +1180,13 @@ static int ucsi_check_cable(struct ucsi_connector *con)
|
|||||||
ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
|
ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
if (con->plug_altmode[0]) {
|
if (con->plug_altmode[0]) {
|
||||||
num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
|
num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
|
||||||
typec_plug_set_num_altmodes(con->plug, num_plug_am);
|
typec_plug_set_num_altmodes(con->plug, num_plug_am);
|
||||||
} else {
|
} else {
|
||||||
typec_plug_set_num_altmodes(con->plug, 0);
|
typec_plug_set_num_altmodes(con->plug, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user