* [PATCH v1] usb: typec: ucsi: Enable notifications before registering connectors
@ 2026-12-02 22:06 Jameson Thies
2026-12-02 22:18 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Jameson Thies @ 2026-12-02 22:06 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman
Cc: linux-usb, linux-kernel, Benson Leung, Andrei Kuchynski,
Jameson Thies
During ucsi_init(), the UCSI driver registers each connector and queries
its initial status before sending SET_NOTIFICATION_ENABLE to enable
connector change notifications. If a port's connection state changes
after its connector is registered but before notifications are enabled,
the PPM does not latch the connector change in CCI and the event is
lost, leaving the port in a stale state.
Move SET_NOTIFICATION_ENABLE before registering connectors so the PPM
latches any connector changes in CCI during port registration. Keep
ucsi->ntfy unset until all connectors are registered so early interrupts
are ignored without sending ACK_CONNECTOR_CHANGE, leaving the change
in CCI for the read_cci() check at the end of ucsi_init() to handle once
registration completes.
Signed-off-by: Jameson Thies <jthies@google.com>
---
drivers/usb/typec/ucsi/ucsi.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 9e453d216c16..ced04c2b66bb 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -2126,6 +2126,13 @@ static int ucsi_init(struct ucsi *ucsi)
for (i = 0; i < ucsi->cap.num_connectors; i++)
lockdep_register_key(&connector[i].lock_key);
+ /* Enable all supported notifications */
+ ntfy = ucsi_get_supported_notifications(ucsi);
+ command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;
+ ret = ucsi_send_command(ucsi, command, NULL, 0);
+ if (ret < 0)
+ goto err_unregister;
+
/* Register all connectors */
for (i = 0; i < ucsi->cap.num_connectors; i++) {
connector[i].num = i + 1;
@@ -2135,20 +2142,12 @@ static int ucsi_init(struct ucsi *ucsi)
}
/*
- * Set ucsi->connector before enabling notifications. A connector
- * change event can be handled as soon as the notifications are
- * enabled below, and ucsi_connector_change() indexes into
+ * Set ucsi->connector before setting ucsi->ntfy. A connector
+ * change event can be handled as soon as ucsi->ntfy is updated
+ * below, and ucsi_connector_change() indexes into
* ucsi->connector, so it must not be NULL at that point.
*/
ucsi->connector = connector;
-
- /* Enable all supported notifications */
- ntfy = ucsi_get_supported_notifications(ucsi);
- command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;
- ret = ucsi_send_command(ucsi, command, NULL, 0);
- if (ret < 0)
- goto err_unregister;
-
ucsi->ntfy = ntfy;
mutex_lock(&ucsi->ppm_lock);
base-commit: 9357829ac604c28510b71b154cb6630af81226ff
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v1] usb: typec: ucsi: Enable notifications before registering connectors
2026-12-02 22:06 [PATCH v1] usb: typec: ucsi: Enable notifications before registering connectors Jameson Thies
@ 2026-12-02 22:18 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-02 22:18 UTC (permalink / raw)
To: Jameson Thies; +Cc: linux-usb
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] usb: typec: ucsi: unordered stores to connector and ntfy in
ucsi_init()
- [Low] usb: typec: ucsi: missing Fixes trailer for ucsi_init()
notification race
--
commit fb6ff5dde5812aba57fdefe58a43defbff6be873
Author: Jameson Thies <jthies@google.com>
> usb: typec: ucsi: Enable notifications before registering connectors
>
> During ucsi_init(), the UCSI driver registers each connector and queries
> its initial status before sending SET_NOTIFICATION_ENABLE to enable
> connector change notifications. If a port's connection state changes
> after its connector is registered but before notifications are enabled,
> the PPM does not latch the connector change in CCI and the event is
> lost, leaving the port in a stale state.
>
> Move SET_NOTIFICATION_ENABLE before registering connectors so the PPM
> latches any connector changes in CCI during port registration. Keep
> ucsi->ntfy unset until all connectors are registered so early interrupts
> are ignored without sending ACK_CONNECTOR_CHANGE, leaving the change
> in CCI for the read_cci() check at the end of ucsi_init() to handle once
> registration completes.
>
> Signed-off-by: Jameson Thies <jthies@google.com>
[Severity: Low]
Should this bug fix include a Fixes: tag for the commit that introduced
the ucsi_init() registration sequence:
Fixes: c1b0bc2dabfa ("usb: typec: Add support for UCSI interface")
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 9e453d216c169..ced04c2b66bbf 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -2126,6 +2126,13 @@ static int ucsi_init(struct ucsi *ucsi)
> for (i = 0; i < ucsi->cap.num_connectors; i++)
> lockdep_register_key(&connector[i].lock_key);
>
> + /* Enable all supported notifications */
> + ntfy = ucsi_get_supported_notifications(ucsi);
> + command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;
> + ret = ucsi_send_command(ucsi, command, NULL, 0);
> + if (ret < 0)
> + goto err_unregister;
> +
> /* Register all connectors */
> for (i = 0; i < ucsi->cap.num_connectors; i++) {
> connector[i].num = i + 1;
> @@ -2135,20 +2142,12 @@ static int ucsi_init(struct ucsi *ucsi)
> }
>
> /*
> - * Set ucsi->connector before enabling notifications. A connector
> - * change event can be handled as soon as the notifications are
> - * enabled below, and ucsi_connector_change() indexes into
> + * Set ucsi->connector before setting ucsi->ntfy. A connector
> + * change event can be handled as soon as ucsi->ntfy is updated
> + * below, and ucsi_connector_change() indexes into
> * ucsi->connector, so it must not be NULL at that point.
> */
> ucsi->connector = connector;
> -
> - /* Enable all supported notifications */
> - ntfy = ucsi_get_supported_notifications(ucsi);
> - command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;
> - ret = ucsi_send_command(ucsi, command, NULL, 0);
> - if (ret < 0)
> - goto err_unregister;
> -
> ucsi->ntfy = ntfy;
[Severity: Medium]
Can ucsi_connector_change() observe ucsi->ntfy with
UCSI_ENABLE_NTFY_CONNECTOR_CHANGE set while ucsi->connector is still
NULL?
Previously, ucsi_send_command() separated the store to ucsi->connector
from the store to ucsi->ntfy and only enabled notifications in the PPM
after ucsi->connector was set. With notifications now enabled in the PPM
before the registration loop, a connector change interrupt can arrive on
another CPU while ucsi_init() writes ucsi->connector and ucsi->ntfy:
CPU0 CPU1
ucsi_init() ucsi_connector_change()
ucsi->connector = connector;
ucsi->ntfy = ntfy;
if (!(ucsi->ntfy & ...))
con = &ucsi->connector[num - 1];
schedule_work(&con->work);
<-- NULL pointer dereference
Because neither side holds a common lock or uses memory barriers, the
stores to ucsi->connector and ucsi->ntfy and the corresponding loads in
ucsi_connector_change() can be reordered on weakly-ordered architectures.
Pairing smp_store_release(&ucsi->ntfy, ntfy) here with
smp_load_acquire(&ucsi->ntfy) in ucsi_connector_change() would enforce
the ordering described in the comment.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202220649.4142702-1-jthies@google.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 22:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 22:06 [PATCH v1] usb: typec: ucsi: Enable notifications before registering connectors Jameson Thies
2026-12-02 22:18 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox