From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Uttkarsh Aggarwal <uttkarsh.aggarwal@oss.qualcomm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Hans de Goede <hdegoede@redhat.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2] usb: typec: ucsi: Set ucsi->connector before enabling notifications
Date: Fri, 9 Oct 2026 13:35:53 +0200 [thread overview]
Message-ID: <asjRmXRRIShLTdFc@black.igk.intel.com> (raw)
In-Reply-To: <20260929092939.1806907-1-uttkarsh.aggarwal@oss.qualcomm.com>
On Tue, Sep 29, 2026 at 02:59:39PM +0530, Uttkarsh Aggarwal wrote:
> 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@vger.kernel.org
> Signed-off-by: Uttkarsh Aggarwal <uttkarsh.aggarwal@oss.qualcomm.com>
Reviewed-by: Heikki Krogerus <heikki.krogeurs@linuc.intel.com>
> ---
> Changes in v2:
> - Add Fixes tag pointing to 0482c34ec6f8 ("usb: ucsi: Fix ucsi->connector race").
> - Add Cc: stable@vger.kernel.org.
> - Link to v1: https://lore.kernel.org/all/20260923060434.2599545-1-uttkarsh.aggarwal@oss.qualcomm.com/
>
> drivers/usb/typec/ucsi/ucsi.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index bef3f9b71d71..8f7b73a9f4f4 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -2122,6 +2122,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;
> @@ -2129,7 +2137,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);
> @@ -2143,6 +2150,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++)
> --
> 2.34.1
--
heikki
prev parent reply other threads:[~2026-10-09 11:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 9:29 [PATCH v2] usb: typec: ucsi: Set ucsi->connector before enabling notifications Uttkarsh Aggarwal
2026-09-30 8:50 ` Peter Chen
2026-10-05 10:03 ` Uttkarsh Aggarwal
2026-10-09 11:35 ` Heikki Krogerus [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=asjRmXRRIShLTdFc@black.igk.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=uttkarsh.aggarwal@oss.qualcomm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox