* [PATCH v2] usb: typec: ucsi: Enable notifications before registering connectors
@ 2026-12-04 1:26 Jameson Thies
0 siblings, 0 replies; only message in thread
From: Jameson Thies @ 2026-12-04 1:26 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, and publish
ucsi->connector with smp_store_release() only after all connectors are
registered. ucsi_connector_change() ignores events while ucsi->connector
is NULL without acknowledging them, so the change stays latched in CCI
for the existing read_cci() check at the end of ucsi_init(). Also set
ucsi->ntfy as soon as notifications are enabled, so the PPM reset in
ucsi_role_cmd() restores the full mask if it runs during registration.
Fixes: c1b0bc2dabfa ("usb: typec: Add support for UCSI interface")
Signed-off-by: Jameson Thies <jthies@google.com>
---
Changes in v2:
- Add Fixes: tag.
- Gate early connector change events on ucsi->connector using
smp_store_release()/smp_load_acquire() instead of ucsi->ntfy.
- Set ucsi->ntfy right after enabling notifications.
drivers/usb/typec/ucsi/ucsi.c | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 9e453d216c16..3c51d1da256e 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1561,7 +1561,9 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num)
{
struct ucsi_connector *con;
- if (!(ucsi->ntfy & UCSI_ENABLE_NTFY_CONNECTOR_CHANGE)) {
+ /* Pairs with smp_store_release() in ucsi_init() */
+ con = smp_load_acquire(&ucsi->connector);
+ if (!con) {
dev_dbg(ucsi->dev, "Early connector change event\n");
return;
}
@@ -1573,7 +1575,7 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num)
return;
}
- con = &ucsi->connector[num - 1];
+ con = &con[num - 1];
if (!test_and_set_bit(EVENT_PENDING, &ucsi->flags))
schedule_work(&con->work);
@@ -2126,22 +2128,6 @@ static int ucsi_init(struct ucsi *ucsi)
for (i = 0; i < ucsi->cap.num_connectors; i++)
lockdep_register_key(&connector[i].lock_key);
- /* Register all connectors */
- for (i = 0; i < ucsi->cap.num_connectors; i++) {
- connector[i].num = i + 1;
- ret = ucsi_register_port(ucsi, &connector[i]);
- if (ret)
- goto err_unregister;
- }
-
- /*
- * 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
- * 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;
@@ -2151,6 +2137,17 @@ static int ucsi_init(struct ucsi *ucsi)
ucsi->ntfy = ntfy;
+ /* Register all connectors */
+ for (i = 0; i < ucsi->cap.num_connectors; i++) {
+ connector[i].num = i + 1;
+ ret = ucsi_register_port(ucsi, &connector[i]);
+ if (ret)
+ goto err_unregister;
+ }
+
+ /* Pairs with smp_load_acquire() in ucsi_connector_change() */
+ smp_store_release(&ucsi->connector, connector);
+
mutex_lock(&ucsi->ppm_lock);
ret = ucsi->ops->read_cci(ucsi, &cci);
mutex_unlock(&ucsi->ppm_lock);
base-commit: 9357829ac604c28510b71b154cb6630af81226ff
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-04 1:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-04 1:26 [PATCH v2] usb: typec: ucsi: Enable notifications before registering connectors Jameson Thies
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®