From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796347603; b=DrkLfN8bB3EojwulbMIXNcoNrtHXbNxU/kmImdEkS8iuzf9qFT27i4r63zFI/sah+IiR Fl9z9cCptzxO2lXLS2FqaZfyAJPKdr03rMm3SqTE5WjjdBuzYEP5rtK4Tove+D13AS6gg /ZYNG0foEp34mrVmMNwdqRWb4KVujcJI56wCJQkZHm1ZTzuEqGLsssIreLHa4FFwoNeTn ZfYriD5rkx/gRcX0aSoNJW3RfPzI7EduiC1BZQzOD2YFTcEHxAeTilDUDU3nEpArLpmkw geE9zWacADcwhNaLgbqDL7LOqPvq5CGaacFHAQkeVmisku4h3LceLurpK6z2fw5Gbjw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796347603; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=ZGT7mhcrt0e8/wmQqJ5N3YVM9Jv2iNdpGAMYU+AIPhY=; b=0nAjhCAHohuTWhXgBGGaJu5xy94NYZF6WznvFeT+/r+K865QsWgY8d7rhpAq5kPwptJE W6+fpmo3Z00v44bFSO3D7wTnrbCajg92Ch6xPzJc5+tLycrN7Wz+qZJw84n8RaP6fCFnJ 8KpYKGWcADtXLPwRBnaWwIhPTkj4QCggEuPB6LFgLJVVQECAhrpLVbkkMlBWjnG+pGRBw W4hixxntzU/uAB/ARiBXT2DGOqBJNFQMXSktsV9FXPNDMnjNfdLUb4blKt23xzOh/swRt 5ZOSpwD5wgXPIIpJMsUMB7mCKX3zlFz/gAGbbGXpmsn/Q29zyqhEoJ6U78L918GRMFQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=bZNkU8ua; arc=none smtp.remote-ip=74.125.82.70 Received: from mail-dl1-f70.google.com (mail-dl1-f70.google.com [74.125.82.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07C27606A322 for ; Fri, 4 Dec 2026 01:26:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 07C27606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=bZNkU8ua Received: by mail-dl1-f70.google.com with SMTP id a92af1059eb24-1b5d5fa8e99so1528653c88.1 for ; Thu, 03 Dec 2026 17:26:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796347601; x=1796952401; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ZGT7mhcrt0e8/wmQqJ5N3YVM9Jv2iNdpGAMYU+AIPhY=; b=bZNkU8ua8KR0VqTcjary6QkV/H1UKsgk7odnHGeeae0m1F+ClZ+SJcVmkSKt6B9Kd+ i+71nQhJw6wBKju7JAk4qHYIMMi4N08hwmlTQy7OZxToOCDyqxL2vQnECjw4WqeENL7V aAlK6TMXANlUzC0jiL6gaYAT6EP1EUW9hHAdy29Po7GwmvykQILjlI49TRNfkZiW8HbT 3ylUxffO33lxoVBY7SbnZxnPIHZOyZFEeT9QPkZl3rpuRihu0O2BThjVO3ad1SZhW7FU 9CwELLuYDQv6lsRJxhoWkSZJITt+V92Rx87iVRpm6ZpluiDJL0+JgZ0Xwdyy5FnOpfPD Q5rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796347601; x=1796952401; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ZGT7mhcrt0e8/wmQqJ5N3YVM9Jv2iNdpGAMYU+AIPhY=; b=LmguyYUjMwITlOJBOx51Sc9tSNrs0AQYwn8XatxhRaV1wZoHwyIhTqPXwT4FI5Omat JXRnPM0iXamsrTngDE9cCzwPRnjf4SZdkc1PK4ghCiGEKOS6XU3YJbN4+Ejx4Dr9EY04 DXBJ9xfQ/HYfTQHfZY9by/iRJ/lbHQsVJdA35cfooRGIgdo5uNvqm+RzQPksLwGzQwzL oshGZc70cI5d5AzyOJJfntAUkOJP6OsQDO7H2A+N8BfeFso9pB2RQBsX0Qfzok48VP4O lisLsK4ktVVeIn31oYjajKKBxD1dg1Aps3U7xJ/GaepuuiX0Jn6vAEVBDxa89sasYyez df0Q== X-Forwarded-Encrypted: i=1; AL+hErHAuxELWLsHUn6EMBtKezu1BMCk7aMms/uSh4n8Wobe03tZ5B2hgz03H7QBlxxhQDAAvnyHkae2Dd+NDp4=@vger.kernel.org X-Gm-Message-State: APuU4Z/WroIOcXAs67hq3sZ1Wk1mH926CFA/mt2QBxPYA1UZKXZeqpBJ +BGlflu/Xsz1Up8n2/v3+Wzea5ptlrmd2Ex6LA7IT2di4OXXWcGegFQbgk7Jh7Se9ZPfZcD2Os5 dowIqYQ== X-Received: from dlak24.prod.google.com ([2002:a05:701b:2918:b0:1b2:cb3a:f87c]) (user=jthies job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6628:b0:14d:cb67:afc4 with SMTP id a92af1059eb24-1b5d71249d2mr1016416c88.41.1796347600671; Thu, 03 Dec 2026 17:26:40 -0800 (PST) Date: Fri, 4 Dec 2026 01:26:37 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204012637.2469388-1-jthies@google.com> Subject: [PATCH v2] usb: typec: ucsi: Enable notifications before registering connectors From: Jameson Thies To: Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Benson Leung , Andrei Kuchynski , Jameson Thies Content-Type: text/plain; charset="UTF-8" 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 --- 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