Commit f87fb985 authored by Hans de Goede's avatar Hans de Goede Committed by Greg Kroah-Hartman

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: bdc62f2b ("usb: typec: ucsi: Simplified registration and I/O API")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217106
Cc: stable@vger.kernel.org
Reviewed-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20230308154244.722337-2-hdegoede@redhat.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fe15c26e
...@@ -1329,7 +1329,7 @@ static int ucsi_register_port(struct ucsi *ucsi, int index) ...@@ -1329,7 +1329,7 @@ static int ucsi_register_port(struct ucsi *ucsi, int index)
static int ucsi_init(struct ucsi *ucsi) static int ucsi_init(struct ucsi *ucsi)
{ {
struct ucsi_connector *con; struct ucsi_connector *con;
u64 command; u64 command, ntfy;
int ret; int ret;
int i; int i;
...@@ -1341,8 +1341,8 @@ static int ucsi_init(struct ucsi *ucsi) ...@@ -1341,8 +1341,8 @@ static int ucsi_init(struct ucsi *ucsi)
} }
/* Enable basic notifications */ /* Enable basic notifications */
ucsi->ntfy = UCSI_ENABLE_NTFY_CMD_COMPLETE | UCSI_ENABLE_NTFY_ERROR; ntfy = UCSI_ENABLE_NTFY_CMD_COMPLETE | UCSI_ENABLE_NTFY_ERROR;
command = UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy; command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;
ret = ucsi_send_command(ucsi, command, NULL, 0); ret = ucsi_send_command(ucsi, command, NULL, 0);
if (ret < 0) if (ret < 0)
goto err_reset; goto err_reset;
...@@ -1374,12 +1374,13 @@ static int ucsi_init(struct ucsi *ucsi) ...@@ -1374,12 +1374,13 @@ static int ucsi_init(struct ucsi *ucsi)
} }
/* Enable all notifications */ /* Enable all notifications */
ucsi->ntfy = UCSI_ENABLE_NTFY_ALL; ntfy = UCSI_ENABLE_NTFY_ALL;
command = UCSI_SET_NOTIFICATION_ENABLE | ucsi->ntfy; command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;
ret = ucsi_send_command(ucsi, command, NULL, 0); ret = ucsi_send_command(ucsi, command, NULL, 0);
if (ret < 0) if (ret < 0)
goto err_unregister; goto err_unregister;
ucsi->ntfy = ntfy;
return 0; return 0;
err_unregister: err_unregister:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment