path: root/drivers
diff options
authorMayank Rana <>2021-06-09 00:35:35 -0700
committerGreg Kroah-Hartman <>2021-06-10 20:02:54 +0200
commitf247f0a82a4f8c3bfed178d8fd9e069d1424ee4e (patch)
tree916f5bdbc8fb4bff84e06354e86833a42b382cb0 /drivers
parente0e8b6abe8c862229ba00cdd806e8598cdef00bb (diff)
usb: typec: ucsi: Clear PPM capability data in ucsi_init() error path
If ucsi_init() fails for some reason (e.g. ucsi_register_port() fails or general communication failure to the PPM), particularly at any point after the GET_CAPABILITY command had been issued, this results in unwinding the initialization and returning an error. However the ucsi structure's ucsi_capability member retains its current value, including likely a non-zero num_connectors. And because ucsi_init() itself is done in a workqueue a UCSI interface driver will be unaware that it failed and may think the ucsi_register() call was completely successful. Later, if ucsi_unregister() is called, due to this stale ucsi->cap value it would try to access the items in the ucsi->connector array which might not be in a proper state or not even allocated at all and results in NULL or invalid pointer dereference. Fix this by clearing the ucsi->cap value to 0 during the error path of ucsi_init() in order to prevent a later ucsi_unregister() from entering the connector cleanup loop. Fixes: c1b0bc2dabfa ("usb: typec: Add support for UCSI interface") Cc: Acked-by: Heikki Krogerus <> Signed-off-by: Mayank Rana <> Signed-off-by: Jack Pham <> Link: Signed-off-by: Greg Kroah-Hartman <>
Diffstat (limited to 'drivers')
1 files changed, 1 insertions, 0 deletions
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index b433169ef6fa..b7d104c80d85 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1253,6 +1253,7 @@ err_unregister:
+ memset(&ucsi->cap, 0, sizeof(ucsi->cap));
return ret;