From: sashiko-bot@kernel.org
To: "Alexey Charkov" <alchark@flipper.net>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH 2/3] usb: typec: tcpm: Leave SRC_VDM_IDENTITY_REQUEST whatever the cable answers
Date: Tue, 17 Nov 2026 11:39:28 +0000 [thread overview]
Message-ID: <sashiko-outbox-218715@kernel.org> (raw)
In-Reply-To: <20261117-tcpm-soft-reset-sop-v1-2-c7e1543828c0@flipper.net>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] usb: typec: tcpm: cable NAK in tcpm_pd_svdm() skips partner
discovery
- [Medium] usb: typec: tcpm: uncancelled VDM in SRC_VDM_IDENTITY_REQUEST
- [Medium] usb: typec: tcpm: sink message in tcpm_pd_handle_msg()
strands port
--
commit 5097e0ac5463844ca0f58a3e399840651ccf8014
Author: Alexey Charkov <alchark@flipper.net>
usb: typec: tcpm: Leave SRC_VDM_IDENTITY_REQUEST whatever the cable answers
This commit replaces the upcoming_state assignment in
SRC_VDM_IDENTITY_REQUEST with a delayed state transition to
SRC_SEND_CAPABILITIES after PD_T_SEND_SOURCE_CAP.
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 8c5be904d7725..947fca918414e 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -6553,7 +6553,11 @@ static void run_state_machine(struct tcpm_port *port)
> /* Cable states */
> case SRC_VDM_IDENTITY_REQUEST:
> mod_vdm_discovery_delayed_work(port, 0);
> - port->upcoming_state = SRC_SEND_CAPABILITIES;
> + /*
> + * Go on with Source_Capabilities whatever becomes of Discover
> + * Identity, unless the cable plug answers sooner
> + */
> + tcpm_set_state(port, SRC_SEND_CAPABILITIES, PD_T_SEND_SOURCE_CAP);
> break;
>
> default:
[Severity: Medium]
If the cable plug replies with CMDT_RSP_NAK in SRC_VDM_IDENTITY_REQUEST,
does leaving the state after PD_T_SEND_SOURCE_CAP skip all SOP partner VDM
discovery once the explicit contract is established?
When CMDT_RSP_NAK arrives over TCPC_TX_SOP_PRIME, tcpm_pd_svdm() assumes
the NAK came from the partner over SOP and marks discovery complete:
drivers/usb/typec/tcpm/tcpm.c:tcpm_pd_svdm() {
...
case CMDT_RSP_NAK:
tcpm_ams_finish(port);
switch (cmd) {
/*
* The cable is not allowed to respond with NAK so this must've happened over SOP
*/
case CMD_DISCOVER_IDENT:
case CMD_DISCOVER_SVID:
tcpm_update_vdm_discovery_state(port, VDM_DISCOVERY_COMPLETE);
break;
...
}
When the timer then moves the port to SRC_SEND_CAPABILITIES and later
SRC_READY under an explicit contract, port->vdm_discovery_state is already
VDM_DISCOVERY_COMPLETE instead of VDM_DISCOVERY_UNKNOWN. SRC_READY skips
tcpm_set_initial_svdm_version(), and tcpm_vdm_discovery_work() returns
immediately without discovering the partner's identity, SVIDs, or alternate
modes.
[Severity: Medium]
Can an in-flight SOP' VDM exchange outlive the PD_T_SEND_SOURCE_CAP timeout
and corrupt partner discovery after the port moves to
SRC_SEND_CAPABILITIES?
If the cable plug responds with CMDT_RSP_BUSY, tcpm_handle_vdm_request()
sets VDM_STATE_WAIT_RSP_BUSY and schedules a retry after PD_T_VDM_BUSY
(100 ms). When that timer fires, port->state is still
SRC_VDM_IDENTITY_REQUEST, so vdm_run_state_machine() queues a new SOP'
transmission across PD_T_SINK_TX (16 ms) and PD_T_VDM_SNDR_RSP (30 ms),
which extends past the 150 ms PD_T_SEND_SOURCE_CAP timeout.
When PD_T_SEND_SOURCE_CAP expires and transitions port->state to
SRC_SEND_CAPABILITIES, the active VDM state machine and AMS are not
cancelled. A subsequent SOP' CMDT_RSP_ACK in tcpm_pd_svdm() or TX failure
in vdm_run_state_machine() then sees port->state !=
SRC_VDM_IDENTITY_REQUEST, advances port->vdm_discovery_state to
VDM_DISCOVERY_CABLE_IDENT, and queues CMD_DISCOVER_SVID on SOP before an
explicit contract or partner identity discovery has happened.
[Severity: Medium]
Does dropping port->upcoming_state = SRC_SEND_CAPABILITIES cause a sink
message handled via tcpm_pd_handle_msg() to strand the port in SRC_READY
without an explicit contract?
While in SRC_VDM_IDENTITY_REQUEST, tcpm_ams_interruptible(port) is true.
If the sink sends a message that takes the default interruptible path in
tcpm_pd_handle_msg() (such as an unsupported message or
PD_CTRL_GET_SINK_CAP), tcpm_set_state(port, ready_state(port), 0) clears
port->delayed_state and cancels the pending PD_T_SEND_SOURCE_CAP timer:
drivers/usb/typec/tcpm/tcpm.c:tcpm_pd_handle_msg() {
...
} else {
port->next_ams = ams;
tcpm_set_state(port, ready_state(port), 0);
/* 6.8.1 process the Message */
tcpm_queue_message(port, message);
}
...
}
Once the queued reply is sent, run_state_machine() enters SRC_READY with
port->upcoming_state == INVALID_STATE and port->explicit_contract == false,
so it never returns to SRC_SEND_CAPABILITIES.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-tcpm-soft-reset-sop-v1-0-c7e1543828c0@flipper.net?part=2
next prev parent reply other threads:[~2026-11-17 11:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 11:15 [PATCH 0/3] usb: typec: tcpm: Fixes for talking to the cable plug as a VCONN source Alexey Charkov
2026-11-17 11:15 ` [PATCH 1/3] usb: typec: tcpm: Keep the Soft_Reset target apart from the VDM one Alexey Charkov
2026-11-17 11:30 ` sashiko-bot
2026-11-17 12:01 ` Alexey Charkov
2026-11-17 11:15 ` [PATCH 2/3] usb: typec: tcpm: Leave SRC_VDM_IDENTITY_REQUEST whatever the cable answers Alexey Charkov
2026-11-17 11:39 ` sashiko-bot [this message]
2026-11-17 12:02 ` Alexey Charkov
2026-11-17 11:15 ` [PATCH 3/3] usb: typec: tcpm: Keep cable plug messages away from the port partner Alexey Charkov
2026-11-17 11:42 ` sashiko-bot
2026-11-17 12:08 ` Alexey Charkov
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=sashiko-outbox-218715@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alchark@flipper.net \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.