From: sashiko-bot@kernel.org
To: "Alexey Charkov" <alchark@flipper.net>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 3/4] usb: typec: tcpm: Leave SRC_VDM_IDENTITY_REQUEST whatever the cable answers
Date: Wed, 18 Nov 2026 08:08:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-220416@kernel.org> (raw)
In-Reply-To: <20261118-tcpm-soft-reset-sop-v2-3-b6decdc95e66@flipper.net>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] usb: typec: tcpm: partner SVID discovery aborted on SOP' NAK
or timeout
- [Low] usb: typec: tcpm: incomplete SOP' VDM cleanup in
run_state_machine()
--
commit b9c2fd6cef3c4af3dcadaf4f8b5d0a17a94ce0f2
Author: Alexey Charkov <alchark@flipper.net>
usb: typec: tcpm: Leave SRC_VDM_IDENTITY_REQUEST whatever the cable answers
This commit transitions the state machine from SRC_VDM_IDENTITY_REQUEST to
SRC_SEND_CAPABILITIES on a cable plug NAK, BUSY, response timeout, or
tTypeCSendSourceCap timeout, and cleans up any pending SOP' VDM request
when entering SRC_SEND_CAPABILITIES.
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index eb30b6efa5a14..cea9e6fc39c00 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm.c
> @@ -2747,6 +2747,12 @@ static int tcpm_pd_svdm(struct tcpm_port *port, struct typec_altmode *adev,
> break;
> case CMDT_RSP_NAK:
> tcpm_ams_finish(port);
> + /* Go on with Source_Capabilities, as after an ACK */
> + if (port->state == SRC_VDM_IDENTITY_REQUEST &&
> + rx_sop_type == TCPC_TX_SOP_PRIME) {
> + tcpm_set_state(port, SRC_SEND_CAPABILITIES, 0);
> + return 0;
> + }
> switch (cmd) {
> /*
> * The cable is not allowed to respond with NAK so this must've happened over SOP
[ ... ]
> @@ -3041,6 +3052,8 @@ static void vdm_run_state_machine(struct tcpm_port *port)
> port->vdm_state = VDM_STATE_ERR_TMOUT;
> if (port->ams != NONE_AMS)
> tcpm_ams_finish(port);
> + if (port->state == SRC_VDM_IDENTITY_REQUEST)
> + tcpm_set_state(port, SRC_SEND_CAPABILITIES, 0);
> break;
> case VDM_STATE_ERR_SEND:
> /*
[Severity: Medium]
Does partner SVID and alternate mode discovery still get aborted when a
cable plug replies with CMDT_RSP_NAK or times out in VDM_STATE_BUSY?
Moving to SRC_SEND_CAPABILITIES here leaves port->cable as NULL. Once the
explicit contract is established in SRC_READY and the port partner ACKs
CMD_DISCOVER_IDENT over TCPC_TX_SOP, tcpm_pd_svdm() sees
IS_ERR_OR_NULL(port->cable) and sends CMD_DISCOVER_IDENT on
TCPC_TX_SOP_PRIME again while port->state is SRC_READY:
drivers/usb/typec/tcpm/tcpm.c:tcpm_pd_svdm() {
...
if (IS_ERR_OR_NULL(port->cable) &&
tcpm_can_communicate_sop_prime(port)) {
*response_tx_sop_type = TCPC_TX_SOP_PRIME;
response[0] = VDO(USB_SID_PD, 1,
typec_get_negotiated_svdm_version(typec),
CMD_DISCOVER_IDENT);
rlen = 1;
}
...
}
When that second SOP' request receives CMDT_RSP_NAK in SRC_READY,
port->state == SRC_VDM_IDENTITY_REQUEST is false, so tcpm_pd_svdm() falls
through to case CMD_DISCOVER_IDENT and sets VDM_DISCOVERY_COMPLETE without
sending CMD_DISCOVER_SVID to the partner. Likewise, if that SOP' request
times out in VDM_STATE_BUSY in SRC_READY, vdm_run_state_machine() sets
VDM_STATE_ERR_TMOUT without advancing to VDM_DISCOVERY_CABLE_IDENT or
queueing CMD_DISCOVER_SVID on TCPC_TX_SOP (unlike VDM_STATE_ERR_SEND).
[ ... ]
> @@ -5550,8 +5563,18 @@ static void run_state_machine(struct tcpm_port *port)
> * Straight from Discover Identity to the cable plug, rather
> * than back through SRC_READY after a message from the sink
> */
> - if (port->prev_state == SRC_VDM_IDENTITY_REQUEST)
> + if (port->prev_state == SRC_VDM_IDENTITY_REQUEST) {
> port->upcoming_state = INVALID_STATE;
> + /* Forget the request if still waiting on the cable plug */
> + if (port->vdm_sop_type == TCPC_TX_SOP_PRIME &&
> + port->vdm_state > VDM_STATE_DONE) {
> + port->vdm_state = VDM_STATE_DONE;
> + port->vdo_data[0] = 0;
> + mod_vdm_delayed_work(port, 0);
> + }
> + if (port->ams == DISCOVER_IDENTITY)
> + tcpm_ams_finish(port);
> + }
> port->caps_count++;
> if (port->caps_count > PD_N_CAPS_COUNT) {
> tcpm_set_state(port, SRC_READY, 0);
[Severity: Low]
Can gating this cleanup on port->prev_state == SRC_VDM_IDENTITY_REQUEST
skip cancelling a pending SOP' VDM when an incoming SOP message from the
sink interrupts SRC_VDM_IDENTITY_REQUEST?
In that case tcpm_pd_handle_msg() transitions SRC_VDM_IDENTITY_REQUEST ->
SRC_READY -> SRC_SEND_CAPABILITIES, so port->prev_state is SRC_READY. For
example, if an unstructured VDM arrives on SOP while vdm_state is waiting
in VDM_STATE_SEND_MESSAGE (PD_T_SINK_TX), tcpm_handle_vdm_request() calls
tcpm_pd_handle_msg(port, PD_MSG_CTRL_NOT_SUPP, NONE_AMS) without resetting
vdm_state, leaving the SOP' VDM timer armed and port->vdo_data[0] set
when SRC_SEND_CAPABILITIES is entered via SRC_READY.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-tcpm-soft-reset-sop-v2-0-b6decdc95e66@flipper.net?part=3
next prev parent reply other threads:[~2026-11-18 8:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 7:26 [PATCH v2 0/4] usb: typec: tcpm: Fixes for talking to the cable plug as a VCONN source Alexey Charkov
2026-11-18 7:26 ` [PATCH v2 1/4] usb: typec: tcpm: Keep the Soft_Reset target apart from the VDM one Alexey Charkov
2026-11-18 7:32 ` sashiko-bot
2026-11-18 7:26 ` [PATCH v2 2/4] usb: typec: tcpm: Stop replaying Source_Capabilities after cable discovery Alexey Charkov
2026-11-18 7:39 ` sashiko-bot
2026-11-18 7:26 ` [PATCH v2 3/4] usb: typec: tcpm: Leave SRC_VDM_IDENTITY_REQUEST whatever the cable answers Alexey Charkov
2026-11-18 8:08 ` sashiko-bot [this message]
2026-11-18 7:26 ` [PATCH v2 4/4] usb: typec: tcpm: Keep cable plug messages away from the port partner Alexey Charkov
2026-11-18 7:51 ` sashiko-bot
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-220416@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.