Skip to content

Commit f247f0a

Browse files
XNUBIAgregkh
authored andcommitted
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: c1b0bc2 ("usb: typec: Add support for UCSI interface") Cc: [email protected] Acked-by: Heikki Krogerus <[email protected]> Signed-off-by: Mayank Rana <[email protected]> Signed-off-by: Jack Pham <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e0e8b6a commit f247f0a

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

drivers/usb/typec/ucsi/ucsi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,7 @@ static int ucsi_init(struct ucsi *ucsi)
12531253
}
12541254

12551255
err_reset:
1256+
memset(&ucsi->cap, 0, sizeof(ucsi->cap));
12561257
ucsi_reset_ppm(ucsi);
12571258
err:
12581259
return ret;

0 commit comments

Comments
 (0)