Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Neil Armstrong <neil.armstrong@linaro.org>
Cc: Badhri Jagan Sridharan <badhri@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Guenter Roeck <groeck@chromium.org>,
	linux-usb@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/2] usb: typec: tcpm: unregister partner altmodes before re-discovery
Date: Wed, 25 Nov 2026 09:34:23 +0100	[thread overview]
Message-ID: <awadjwZUgA_U7ySC@black.igk.intel.com> (raw)
In-Reply-To: <20261120-topic-tcpm-core-fixes-v1-1-c753d1d286bb@linaro.org>

On Fri, Nov 20, 2026 at 10:56:16AM +0100, Neil Armstrong wrote:
> svdm_consume_identity() clears port->mode_data when a Discover Identity
> ACK is received. mode_data.altmodes is also the count used to walk
> port->partner_altmode[] when unregistering the partner alternate modes,
> so if the partner altmodes from an earlier discovery are still
> registered, clearing it leaks them and the following Discover Modes
> round registers a second set for the same partner.
> 
> Unregister the partner altmodes before clearing mode_data, and reuse
> the new helper in tcpm_unregister_altmodes().
> 
> Cc: stable@vger.kernel.org
> Fixes: f0690a25a140 ("staging: typec: USB Type-C Port Manager (tcpm)")
> Assisted-by: LLM
> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/tcpm/tcpm.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index bb90211660ca..1d007e59a2bf 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -2060,6 +2060,17 @@ static int tcpm_queue_vdm_unlocked(struct tcpm_port *port, const u32 header,
>  	return ret;
>  }
>  
> +static void tcpm_unregister_partner_altmodes(struct tcpm_port *port)
> +{
> +	struct pd_mode_data *modep = &port->mode_data;
> +	int i;
> +
> +	for (i = 0; i < modep->altmodes && i < ALTMODE_DISCOVERY_MAX; i++) {
> +		typec_unregister_altmode(port->partner_altmode[i]);
> +		port->partner_altmode[i] = NULL;
> +	}
> +}
> +
>  static void svdm_consume_identity(struct tcpm_port *port, const u32 *p, int cnt)
>  {
>  	u32 vdo = p[VDO_INDEX_IDH];
> @@ -2068,6 +2079,7 @@ static void svdm_consume_identity(struct tcpm_port *port, const u32 *p, int cnt)
>  	if (cnt <= VDO_INDEX_PRODUCT)
>  		return;
>  
> +	tcpm_unregister_partner_altmodes(port);
>  	memset(&port->mode_data, 0, sizeof(port->mode_data));
>  
>  	port->partner_ident.id_header = vdo;
> @@ -5129,10 +5141,7 @@ static void tcpm_unregister_altmodes(struct tcpm_port *port)
>  	struct pd_mode_data *modep_prime = &port->mode_data_prime;
>  	int i;
>  
> -	for (i = 0; i < modep->altmodes && i < ALTMODE_DISCOVERY_MAX; i++) {
> -		typec_unregister_altmode(port->partner_altmode[i]);
> -		port->partner_altmode[i] = NULL;
> -	}
> +	tcpm_unregister_partner_altmodes(port);
>  	for (i = 0; i < modep_prime->altmodes && i < ALTMODE_DISCOVERY_MAX; i++) {
>  		typec_unregister_altmode(port->plug_prime_altmode[i]);
>  		port->plug_prime_altmode[i] = NULL;
> 
> -- 
> 2.34.1

-- 
heikki

  reply	other threads:[~2026-11-25  8:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  9:56 [PATCH 0/2] usb: tcpm: partner sink capabilities and altmodes leak fixes Neil Armstrong
2026-11-20  9:56 ` [PATCH 1/2] usb: typec: tcpm: unregister partner altmodes before re-discovery Neil Armstrong
2026-11-25  8:34   ` Heikki Krogerus [this message]
2026-11-20  9:56 ` [PATCH 2/2] usb: typec: tcpm: unregister stale partner sink capabilities Neil Armstrong

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=awadjwZUgA_U7ySC@black.igk.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=badhri@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=groeck@chromium.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=stable@vger.kernel.org \
    /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