Linux USB
 help / color / mirror / Atom feed
* [PATCH v1] usb: typec: tcpm: Clear pps_data in tcpm_reset_port()
@ 2026-12-03 14:00 Kyle Tso
  2026-12-03 14:25 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Kyle Tso @ 2026-12-03 14:00 UTC (permalink / raw)
  To: Badhri Jagan Sridharan, Heikki Krogerus, Greg Kroah-Hartman
  Cc: Amit Sunil Dhamne, Guenter Roeck, linux-usb, Kyle Tso

tcpm_reset_port() currently clears only port->pps_data.supported on
port detach or reset, leaving port->pps_data.active and the remaining
fields (min_volt, max_volt, max_curr, and req_*) stale from a prior
PPS session.

Because the TCPM power_supply getters check port->pps_data.active, the
voltage and current limit properties continue reporting the previous
PPS adapter's bounds even after detach. When a new source is attached
and charging is enabled in SNK_DISCOVERY, POWER_SUPPLY_PROP_ONLINE
also falsely reports TCPM_PSY_PPS_ONLINE instead of
TCPM_PSY_FIXED_ONLINE (along with the stale PPS limits instead of the
5V Type-C limits) until a new PD contract is accepted or
SNK_HARD_RESET_SINK_OFF runs (if reached).

Clear the entire port->pps_data structure in tcpm_reset_port(),
matching SNK_HARD_RESET_SINK_OFF, before notifying port->psy.

Fixes: 2eadc33f40d4 ("typec: tcpm: Add core support for sink side PPS")
Cc: stable@vger.kernel.org
Reviewed-by: Amit Sunil Dhamne <amitsd@google.com>
Reviewed-by: Badhri Jagan Sridharan <badhri@google.com>
Signed-off-by: Kyle Tso <kyletso@google.com>
---
 drivers/usb/typec/tcpm/tcpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index ca38e05f831a..72b08d69ff80 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -5178,7 +5178,7 @@ static void tcpm_reset_port(struct tcpm_port *port)
 	tcpm_typec_disconnect(port);
 	port->attached = false;
 	port->pd_capable = false;
-	port->pps_data.supported = false;
+	memset(&port->pps_data, 0, sizeof(port->pps_data));
 	tcpm_set_partner_usb_comm_capable(port, false);
 
 	/*

base-commit: 9357829ac604c28510b71b154cb6630af81226ff
-- 
2.56.1.911.g883d8bcb20-goog


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

* Re: [PATCH v1] usb: typec: tcpm: Clear pps_data in tcpm_reset_port()
  2026-12-03 14:00 [PATCH v1] usb: typec: tcpm: Clear pps_data in tcpm_reset_port() Kyle Tso
@ 2026-12-03 14:25 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 14:25 UTC (permalink / raw)
  To: Kyle Tso; +Cc: linux-usb

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: typec: tcpm: unsynchronized early pps_data memset in
  tcpm_reset_port()
--

commit 07c97444e7154a6e5c8ed5b6cc157c2333dc910a
Author: Kyle Tso <kyletso@google.com>

usb: typec: tcpm: Clear pps_data in tcpm_reset_port()

This commit clears the entire port->pps_data structure in tcpm_reset_port()
instead of only clearing port->pps_data.supported.

> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index ca38e05f831a7..72b08d69ff808 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -5178,7 +5178,7 @@ static void tcpm_reset_port(struct tcpm_port *port)
>  	tcpm_typec_disconnect(port);
>  	port->attached = false;
>  	port->pd_capable = false;
> -	port->pps_data.supported = false;
> +	memset(&port->pps_data, 0, sizeof(port->pps_data));
>  	tcpm_set_partner_usb_comm_capable(port, false);
>  
>  	/*

[Severity: Low]
Can clearing port->pps_data here cause tcpm_psy_get_online() to transiently
report TCPM_PSY_FIXED_ONLINE during a PPS detach or reset?

tcpm_reset_port() clears port->pps_data.active before sleeping TCPC bus
calls (set_pd_rx() and set_vbus() in tcpm_init_vbus()) and before
tcpm_init_vbus() sets port->vbus_charge to false.  Because
tcpm_psy_get_online() does not take port->lock, a concurrent power_supply
reader can observe the intermediate state:

CPU0                                CPU1
tcpm_reset_port()
  memset(&port->pps_data, 0, ...)
  set_pd_rx(..., false)
                                    tcpm_psy_get_online()
                                      port->vbus_charge == true
                                      port->pps_data.active == false
                                      <-- returns TCPM_PSY_FIXED_ONLINE
  tcpm_init_vbus()
    port->vbus_charge = false

Separately, struct pd_pps_data places min_volt, max_volt, and max_curr
before active, so memset() zeroes those fields before clearing active.
Concurrent lockless readers such as tcpm_psy_get_voltage_max() can race
with this memset() and observe active as true with zeroed or torn bounds.

Clearing port->pps_data after tcpm_init_vbus() would avoid the
TCPM_PSY_FIXED_ONLINE window once port->vbus_charge is false.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203140023.2275666-1-kyletso@google.com?part=1

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

end of thread, other threads:[~2026-12-03 14:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 14:00 [PATCH v1] usb: typec: tcpm: Clear pps_data in tcpm_reset_port() Kyle Tso
2026-12-03 14:25 ` sashiko-bot

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