From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385670; b=rKptk7EE2ThlBYcI1Vdj5gazaWFl+7tG7lQvFkK6Tb7H4C1AdW9kc756uvq1HYyLI+Cl V4j29rM5J/Gi+0qlXGH++FQ3F5+pNdwkl+hbJBErWjy0wnod+bpUl79tsVxYthVPyq9wJ ddGZeE89pCXSRjWVRj8RiVSZpNB4Ghi73ccoxqQ+8o22hm1bJ7c3VFhS5OZJ7gF1hWHqk YiYbWpgG7cbuf0eRReHuGwDFI1UUAjPmCO6sx5RHzHW0Gxh/PWap9VP7VWEy7O2w6laOB jQzZZPAZH2NwSZcUvFTRWe+8/8+XWDUVHetG/Jc42AnQe+EhyPricU2LymMBE/Q13Jw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385670; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=hYfN6AmjVDQoRhfSzvDC0HGSQnVbyRiyKJKhqYNMn/o=; b=xYCDrnM69K+AiJcSgG4iMtFmtRr19kIBFqdZmvtoTc5tOypq2j0wf8xvWujn1APZh9TF MqC2FWnx5Sc4DZfx8EU48mON8XPZfkn7w7TWp3wS2dTRnGPPT2L+mKUrV5Tn9wmtCopCL a0UbO9+ltPtjN9+9M+0WUhMq1mobWdEMeAThJE7DYqf2WVyVyjOWNvkMVMkSmMe+mkA5N m1tmSNnAQkEW4AuYV4jQc4JhfxeGiSOdP3RmnX9QETddsz6FKMnpqiTnf2Omnra1qfrvt Wvr7fFAJ/oJcFnf3VOOEqNmuS0oVPTvkhWfw5HuqDnAKjvZzUe0wfSe5hARdvRhK8jQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="bYyjXdn/"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A9FC606A322; Fri, 4 Dec 2026 12:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=bYyjXdn/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2F811F000CE; Fri, 4 Dec 2026 12:01:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385670; bh=hYfN6AmjVDQoRhfSzvDC0HGSQnVbyRiyKJKhqYNMn/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bYyjXdn/rIjYN+xRck4s3dYD2prD6BK4xQ5phY/DwVr5GuCKVu8lwJFHXZ0PJ0sIU 1YehJuOB4CRsJA+imACXDk1gbhal/4ESF+hftCyWCrU34vr808Og38xS7xCtpCjQ2m cT6lbDXHlzjl7zoOCuC0mj2SCKM2KY+YyQ+5Im/s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Uttkarsh Aggarwal , Peter Chen , Heikki Krogerus Subject: [PATCH 6.6 0646/1167] usb: typec: ucsi: Set ucsi->connector before enabling notifications Date: Fri, 4 Dec 2026 19:01:13 +0900 Message-ID: <20261204100718.885529827@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Uttkarsh Aggarwal commit 5b4b83c2ffe8740f6f3e54ea4d4962a62c063ef1 upstream. In ucsi_init(), ucsi->connector is assigned only after the UCSI_SET_NOTIFICATION_ENABLE command completes. But once that command is sent, the PPM is free to raise a connector change notification at any time, which is handled through: ucsi_notify_common() -> ucsi_connector_change() ucsi_connector_change() indexes into ucsi->connector to get the connector and schedule its work item. If this notification arrives before ucsi_init() reaches the "ucsi->connector = connector;" line, ucsi->connector is still NULL and the driver crashes dereferencing it. Fix this by setting ucsi->connector right after the connectors are registered, before notifications are enabled, so it is always valid by the time a connector change event can be delivered. Also clear ucsi->connector in the err_unregister path so it isn't left pointing at freed memory if a later step in ucsi_init() fails. Fixes: 0482c34ec6f8 ("usb: ucsi: Fix ucsi->connector race") Cc: stable Signed-off-by: Uttkarsh Aggarwal Reviewed-by: Peter Chen Reviewed-by: Heikki Krogerus Link: https://patch.msgid.link/20260929092939.1806907-1-uttkarsh.aggarwal@oss.qualcomm.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/ucsi/ucsi.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -1528,6 +1528,14 @@ static int ucsi_init(struct ucsi *ucsi) 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; @@ -1535,7 +1543,6 @@ static int ucsi_init(struct ucsi *ucsi) if (ret < 0) goto err_unregister; - ucsi->connector = connector; ucsi->ntfy = ntfy; mutex_lock(&ucsi->ppm_lock); @@ -1549,6 +1556,7 @@ static int ucsi_init(struct ucsi *ucsi) return 0; err_unregister: + ucsi->connector = NULL; for (con = connector; con->port; con++) ucsi_unregister_port(con); for (i = 0; i < ucsi->cap.num_connectors; i++)