From: Amit Sunil Dhamne <amitsd@google.com>
To: Josef Bacik <josef@toxicpanda.com>
Cc: Alan Stern <stern@rowland.harvard.edu>,
linux-kernel@vger.kernel.org,
Badhri Jagan Sridharan <badhri@google.com>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable <stable@kernel.org>,
linux-usb@vger.kernel.org
Subject: Re: [PATCH 12/19] usb: typec: tcpci: don't act on unread alerts
Date: Mon, 2 Nov 2026 14:23:57 -0800 [thread overview]
Message-ID: <d1557c0a-e82a-4eb6-bc91-d8106e1961f2@google.com> (raw)
In-Reply-To: <20261027-llm-usb-v1-12-b9751ddb9c7c@linuxfoundation.org>
Hi,
On 10/27/26 7:57 AM, Greg Kroah-Hartman wrote:
> From: Josef Bacik <josef@toxicpanda.com>
>
> tcpci_irq() ignores the result of nearly all its register reads.
>
> If the first read of TCPC_ALERT fails, "status" is an unwritten variable,
> and its bits decide which events are reported to the port manager: among
> them a hard reset, which drops VBUS. If the read at the end of the function
> fails, "status" keeps the alerts which have just been handled: they are
> handled again, for as long as the read fails.
>
> In the receive branch the byte count, the header and the payload are not
> checked: a count made of stack content trips the WARN_ON(), and a message
> made of stack content is handed to tcpm_pd_receive(). A failed read of the
> frame type returns a negative errno as irqreturn_t, with RX_STATUS still
> set.
>
> The handler must not simply return in these cases. Nine in-tree boards
> connect ALERT# to an edge triggered interrupt: as long as an alert is
> pending the line stays low, and there is no further edge. That is what the
> read at the end is for.
>
> So read the alert register through a helper which tries three times and
> reports "no alert" if that fails: after a failed first read the function
> falls through to the read at the end. Drop a message which cannot be read,
> but clear RX_STATUS, to release the line. Don't take an unread power status
> mask for a reset of the TCPC. Return IRQ_HANDLED if any round has found an
> alert, not only the first one.
>
nit: This commit is quite verbose. It would be better if it were more
succinct and to the point. For example, the last paragraph narrates the
code rather than stating the intent.
> Fixes: 74e656d6b055 ("staging: typec: Type-C Port Controller Interface driver (tcpci)")
> Fixes: 77e85107a771 ("usb: typec: tcpci: support edge irq")
> Fixes: b691a07c5f64 ("usb: typec: tcpci: pass correct rx_type to tcpm_pd_receive()")
> Cc: Badhri Jagan Sridharan <badhri@google.com>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: stable <stable@kernel.org>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
> drivers/usb/typec/tcpm/tcpci.c | 64 +++++++++++++++++++++++++++++++-----------
> 1 file changed, 47 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
> index 6717ac914c6a..26c62216a813 100644
> --- a/drivers/usb/typec/tcpm/tcpci.c
> +++ b/drivers/usb/typec/tcpm/tcpci.c
> @@ -715,17 +715,34 @@ static int tcpci_init(struct tcpc_dev *tcpc)
> return 0;
> }
>
> +/*
> + * An edge triggered ALERT# does not fire again while an alert is pending, so
> + * don't give up after one failed transfer. No alert if it cannot be read.
> + */
> +static u16 tcpci_read_alert(struct tcpci *tcpci)
> +{
> + u16 status;
> + int i;
> +
> + for (i = 0; i < 3; i++)
> + if (!tcpci_read16(tcpci, TCPC_ALERT, &status))
> + return status;
Retrying immediately on a transient bus failure is unlikely to help. Add
a small delay before retrying. Please keep in mind the Type-C/PD
deadlines when selecting a delay value.
> +
Please add some error log here to indicate consecutive alert read failures.
> + return 0;
> +}
> +
> irqreturn_t tcpci_irq(struct tcpci *tcpci)
> {
> u16 status;
> int ret;
> - int irq_ret;
> + int irq_ret = 0;
> unsigned int raw;
>
> - tcpci_read16(tcpci, TCPC_ALERT, &status);
> - irq_ret = status & tcpci->alert_mask;
> + status = tcpci_read_alert(tcpci);
>
> process_status:
> + irq_ret |= status & tcpci->alert_mask;
> +
> /*
> * Clear alert status for everything except RX_STATUS, which shouldn't
> * be cleared until we have successfully retrieved message.
> @@ -738,12 +755,12 @@ irqreturn_t tcpci_irq(struct tcpci *tcpci)
> tcpm_cc_change(tcpci->port);
>
> if (status & TCPC_ALERT_POWER_STATUS) {
> - regmap_read(tcpci->regmap, TCPC_POWER_STATUS_MASK, &raw);
> + ret = regmap_read(tcpci->regmap, TCPC_POWER_STATUS_MASK, &raw);
> /*
> * If power status mask has been reset, then the TCPC
> * has reset.
> */
> - if (raw == 0xff)
> + if (!ret && raw == 0xff)
> tcpm_tcpc_reset(tcpci->port);
> else
> tcpm_vbus_change(tcpci->port);
> @@ -755,7 +772,10 @@ irqreturn_t tcpci_irq(struct tcpci *tcpci)
> enum tcpm_transmit_type rx_type;
> u16 header;
>
> - regmap_read(tcpci->regmap, TCPC_RX_BYTE_CNT, &cnt);
> + ret = regmap_read(tcpci->regmap, TCPC_RX_BYTE_CNT, &cnt);
> + if (ret)
> + goto rx_done;
> +
> /*
> * 'cnt' corresponds to READABLE_BYTE_COUNT in section 4.4.14
> * of the TCPCI spec [Rev 2.0 Ver 1.0 October 2017] and is
> @@ -767,26 +787,36 @@ irqreturn_t tcpci_irq(struct tcpci *tcpci)
> else
> payload_cnt = 0;
>
> - tcpci_read16(tcpci, TCPC_RX_HDR, &header);
> + ret = tcpci_read16(tcpci, TCPC_RX_HDR, &header);
> + if (ret)
> + goto rx_done;
> +
> msg.header = cpu_to_le16(header);
>
> if (WARN_ON(payload_cnt > sizeof(msg.payload)))
> payload_cnt = sizeof(msg.payload);
>
> - if (payload_cnt > 0)
> - regmap_raw_read(tcpci->regmap, TCPC_RX_DATA,
> - &msg.payload, payload_cnt);
> + if (payload_cnt > 0) {
> + ret = regmap_raw_read(tcpci->regmap, TCPC_RX_DATA,
> + &msg.payload, payload_cnt);
> + if (ret)
> + goto rx_done;
> + }
>
> ret = regmap_read(tcpci->regmap, TCPC_RX_BUF_FRAME_TYPE, &rx_type);
> - if (ret)
> - return ret;
>
> - /* Read complete, clear RX status alert bit */
> +rx_done:
Worth logging when you're dropping RX packets (due to ret!=0) given that
the tcpc has already sent a GoodCRC.
Regards,
Amit
next prev parent reply other threads:[~2026-11-02 22:24 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 14:57 [PATCH 00/19] USB: a bunch of llm-found fixes Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 01/19] usb: core: sysfs: take the port lock to read the BOS Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 02/19] USB: core: signal the end of an sg request last Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 03/19] usbip: vudc: free the unlink item if the send fails Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 04/19] usb: host: oxu210hp-hcd: fix oxu_qh_alloc() deadlock Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 05/19] usb: cdns3: switch the role unlocked on resume Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 06/19] usb: gadget: snps_udc_plat: lock out the interrupt Greg Kroah-Hartman
2026-10-27 18:17 ` Herve Codina
2026-10-27 14:57 ` [PATCH 07/19] usb: gadget: bdc: the resume callback is optional Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 08/19] usb: gadget: uvc: fix oops on a premature STREAMON Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 09/19] usb: gadget: f_fs: let the request keep its fence Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 10/19] usb: host: ehci-orion: fix the probe without DT Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 11/19] usb: typec: tcpm: don't wait for the VDM discovery work Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 12/19] usb: typec: tcpci: don't act on unread alerts Greg Kroah-Hartman
2026-11-02 22:23 ` Amit Sunil Dhamne [this message]
2026-10-27 14:57 ` [PATCH 13/19] usb: typec: anx7411: zero on-stack alt mode descriptors Greg Kroah-Hartman
2026-10-28 16:20 ` Benson Leung
2026-10-27 14:57 ` [PATCH 14/19] usb: typec: mux: it5205: fix oops on accessory modes Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 15/19] usb: typec: mux: tusb1046: " Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 16/19] usb: renesas_usbhs: link URBs with interrupts disabled Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 17/19] usb: renesas_usbhs: unlink the URB if it is not queued Greg Kroah-Hartman
2026-10-27 14:57 ` [PATCH 18/19] usb: isp1760: wait for the TT clear in endpoint_disable Greg Kroah-Hartman
2026-10-27 15:21 ` Rui Miguel Silva
2026-10-27 14:57 ` [PATCH 19/19] usb: dwc2: " Greg Kroah-Hartman
2026-11-02 9:04 ` [PATCH 00/19] USB: a bunch of llm-found fixes Romain Gantois
2026-11-02 9:07 ` Romain Gantois
2026-11-02 9:06 ` Romain Gantois
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=d1557c0a-e82a-4eb6-bc91-d8106e1961f2@google.com \
--to=amitsd@google.com \
--cc=badhri@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=josef@toxicpanda.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stable@kernel.org \
--cc=stern@rowland.harvard.edu \
/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
all inboxes | Powered by JetHome®