Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 0/2] usb: tcpm: partner sink capabilities and altmodes leak fixes
@ 2026-11-20  9:56 Neil Armstrong
  2026-11-20  9:56 ` [PATCH 1/2] usb: typec: tcpm: unregister partner altmodes before re-discovery Neil Armstrong
  2026-11-20  9:56 ` [PATCH 2/2] usb: typec: tcpm: unregister stale partner sink capabilities Neil Armstrong
  0 siblings, 2 replies; 4+ messages in thread
From: Neil Armstrong @ 2026-11-20  9:56 UTC (permalink / raw)
  To: Badhri Jagan Sridharan, Heikki Krogerus, Greg Kroah-Hartman,
	Guenter Roeck
  Cc: linux-usb, Neil Armstrong, stable

Two fixes for potential leaks where neither the partner
sink capabilities and altmodes were unregistered properly.

Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
Neil Armstrong (2):
      usb: typec: tcpm: unregister partner altmodes before re-discovery
      usb: typec: tcpm: unregister stale partner sink capabilities

 drivers/usb/typec/tcpm/tcpm.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
---
base-commit: adcad7f4e6332cff3d6d7165f41584899f598534
change-id: 20261120-topic-tcpm-core-fixes-5cb1a6a9838c

Best regards,
--  
Neil Armstrong <neil.armstrong@linaro.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] usb: typec: tcpm: unregister partner altmodes before re-discovery
  2026-11-20  9:56 [PATCH 0/2] usb: tcpm: partner sink capabilities and altmodes leak fixes Neil Armstrong
@ 2026-11-20  9:56 ` Neil Armstrong
  2026-11-25  8:34   ` Heikki Krogerus
  2026-11-20  9:56 ` [PATCH 2/2] usb: typec: tcpm: unregister stale partner sink capabilities Neil Armstrong
  1 sibling, 1 reply; 4+ messages in thread
From: Neil Armstrong @ 2026-11-20  9:56 UTC (permalink / raw)
  To: Badhri Jagan Sridharan, Heikki Krogerus, Greg Kroah-Hartman,
	Guenter Roeck
  Cc: linux-usb, Neil Armstrong, stable

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>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] usb: typec: tcpm: unregister stale partner sink capabilities
  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-20  9:56 ` Neil Armstrong
  1 sibling, 0 replies; 4+ messages in thread
From: Neil Armstrong @ 2026-11-20  9:56 UTC (permalink / raw)
  To: Badhri Jagan Sridharan, Heikki Krogerus, Greg Kroah-Hartman,
	Guenter Roeck
  Cc: linux-usb, Neil Armstrong, stable

tcpm_register_sink_caps() registers a new "sink-capabilities" device
under the partner USB PD object every time a Sink_Capabilities message
is received, but the previously registered one is only removed on
detach.

sink_cap_done is cleared on Hard Reset, so the sink capabilities are
queried and registered again on the same partner: registering a second
device with the same name under the same parent fails, and the stale
capabilities stay exposed in sysfs.

Unregister the previous capabilities before registering the new ones.

Cc: stable@vger.kernel.org
Fixes: 8203d26905ee ("usb: typec: tcpm: Register USB Power Delivery Capabilities")
Assisted-by: LLM
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
 drivers/usb/typec/tcpm/tcpm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 1d007e59a2bf..c5a4c0b6da16 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -3563,6 +3563,8 @@ static int tcpm_register_sink_caps(struct tcpm_port *port)
 	if (IS_ERR(cap))
 		return PTR_ERR(cap);
 
+	if (port->partner_sink_caps)
+		usb_power_delivery_unregister_capabilities(port->partner_sink_caps);
 	port->partner_sink_caps = cap;
 
 	return 0;

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] usb: typec: tcpm: unregister partner altmodes before re-discovery
  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
  0 siblings, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2026-11-25  8:34 UTC (permalink / raw)
  To: Neil Armstrong
  Cc: Badhri Jagan Sridharan, Greg Kroah-Hartman, Guenter Roeck,
	linux-usb, stable

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-25  8:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-11-20  9:56 ` [PATCH 2/2] usb: typec: tcpm: unregister stale partner sink capabilities Neil Armstrong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox