From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796347602; b=zkSzK2JZ9dQ4iu9wyW2ORGzDCUrjbEDqcpdMcdOonbpXYD95+Wc96FczDV5vbbsaQukp SW7WlsbEnLLuYpFWuQQbbHeafgq84OjYwF1xK1oX2ueV9VHT2rVNFxXQ4FnxxeAWrwxAp mXk1+nlVJoQF2Jnr/ljeT85VnTLxZN7bVQE3SdTDsaDS8TJu34OcpGimMsYCxeIdapNeG QMr0qdGNNn75hTlTtm04bItgnFtiShffGm/BQs7rLV8nZbjwr20/YIeiRVR1zh2RbCu9k llAT6gblOXaFFImPzuWnUtop6gmCFU1RMxaS0qaFClftfz+Ei9hE8eTLNtDfwyqtcuw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796347602; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:Mime-Version:X-Mailer:Message-ID: Subject:From:To:Cc:Content-Type; bh=ZGT7mhcrt0e8/wmQqJ5N3YVM9Jv2iNdpGAMYU+AIPhY=; b=B+ia60lz190ZPjNFW5Ibw0EB5QWjzy4EHYSZ6UTDn1xS8AVEszL+oM0D8OuUyi7nUtB7 HwdKdF8RwRqAfDYepaCVOkBgIbvhWIMxDJmxsvTPEWOzRkwAAwKpVrlaTxhj8liD40tTb g9mcvusJ2UWIu57z9p4X1jg+cvPByMVJdV/QYuh0S07+m2WBrtG6D4WT9RjkNcgUX8ZC1 BLmLd9anvkOsRnc42uWF+HVNdZ5i+bLrLgjGzBI+vPw+q022sHBJnCW2xf7XACDV31nFa nNlyyDjlaiGG2Zu6tI7UVRmrg0K1Jv3Aw01stzDKvkNXuL8eyF+C5pnX4WBgyWZpXZw== 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.69 Received: from mail-dl1-f69.google.com (mail-dl1-f69.google.com [74.125.82.69]) (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 09046606A32C for ; Fri, 4 Dec 2026 01:26:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 09046606A32C 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-f69.google.com with SMTP id a92af1059eb24-139b62317d0so1033822c88.0 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=2LF6Vce5kYeN49E30N1LDFSOGzkpKMykF9dhuYWi8Bi/9YFvIlztwhJM7jKC6sVFJJ 4syLZakh4+BxOMhfqbhmZOAZ1J75nXrZ9+iEVXEy+6QLFPnYKzB8JQ6frMefpRKi/9uP kxFCyMA+tY+E1teIoQcDeS9oYtLPky1Y0yxyXMo+kLQRNZctkmMxqbtIhuUOTPyvFoOD 8pEs2R4POEuFAm8vWwbZpLSpjBnp4xTbLddAxQklyrBSR4HknYHYeH79ll1+TQFfEos6 rvYaT3H6zLJVHVCc18f4ZLsUNWCMSnkE8jvn0wQlFbQgzMuGht0oVgk7zd/QWne80iUd Axyg== X-Gm-Message-State: APuU4Z/WxQJqj8F8gkOW6Zjg03sQv7Vq1NasCDHgM5C2ZlQK4JQ7LWLD NbPSUjbGibgTWI4owzxlWAH4eJEsX/CUmUd9D5ZzkaEElSlRY5ahcWr+lLCGBiGRXPCHSrmTHLL 2fOdGnw== 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-usb@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