From: sashiko-bot@kernel.org
To: ChunYuZhiQiang <chunyuzhiqiang@yinhe.ht>
Cc: imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [RFC PATCH v2 1/1] spi: fsl-lpspi: add atomic transfer support
Date: Fri, 27 Nov 2026 07:59:23 +0000 [thread overview]
Message-ID: <sashiko-outbox-236849@kernel.org> (raw)
In-Reply-To: <20261127073454.351296-2-chunyuzhiqiang@yinhe.ht>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] spi: fsl-lpspi: RX watermark deadlock in
fsl_lpspi_pio_xfer_atomic()
- [High] spi: fsl-lpspi: SR_TCF timeout with TCR_CONT in
fsl_lpspi_pio_xfer_atomic()
- [High] spi: fsl-lpspi: TCR_CONTC set after reset in
fsl_lpspi_transfer_atomic()
- [Medium] spi: fsl-lpspi: CS asserted before CPOL/CPHA in
fsl_lpspi_transfer_atomic()
- [Medium] spi: fsl-lpspi: wrong word-size check in
fsl_lpspi_transfer_atomic()
- [Medium] spi: fsl-lpspi: missing actual_length in
fsl_lpspi_transfer_atomic()
- [Low] spi: fsl-lpspi: unedited AI assistance placeholder note in
commit message
--
commit 82f1685db0bb8dc824359af32b18e4e751d9a022
Author: ChunYuZhiQiang <chunyuzhiqiang@yinhe.ht>
spi: fsl-lpspi: add atomic transfer support
This commit adds a transfer_atomic() callback for the i.MX LPSPI controller
using polled PIO, caches the peripheral clock rate for atomic context, and
registers sys-off handlers to runtime-resume the controller before shutdown
or restart.
> This patch was prepared with AI assistance; the submitter must review it
> before submission.
[Severity: Low]
This looks like an unedited reminder from an AI tool that should be
removed from the commit message before merging.
> diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
> index ed395f822dab1..e37761d05cd5e 100644
> --- a/drivers/spi/spi-fsl-lpspi.c
> +++ b/drivers/spi/spi-fsl-lpspi.c
[ ... ]
> @@ -774,6 +785,114 @@ static int fsl_lpspi_pio_transfer(struct fsl_lpspi_data *fsl_lpspi,
> return ret;
> }
>
> +static int fsl_lpspi_pio_xfer_atomic(struct fsl_lpspi_data *fsl_lpspi,
> + struct spi_transfer *t)
> +{
> + u32 sr, timeout_us;
> + int ret;
> +
> + /* One frame plus margin, at least 1ms. */
> + timeout_us = DIV_ROUND_UP(8 * USEC_PER_SEC, fsl_lpspi->config.speed_hz);
> + timeout_us = max(timeout_us * 2, 1000U);
> +
> + fsl_lpspi->tx_buf = t->tx_buf;
> + fsl_lpspi->rx_buf = t->rx_buf;
> + fsl_lpspi->remain = t->len;
> +
> + while (fsl_lpspi->remain) {
> + ret = readl_poll_timeout_atomic(fsl_lpspi->base + IMX7ULP_SR,
> + sr, sr & SR_TDF, 0, timeout_us);
> + if (ret)
> + return ret;
> + fsl_lpspi->tx(fsl_lpspi);
> +
> + ret = readl_poll_timeout_atomic(fsl_lpspi->base + IMX7ULP_SR,
> + sr, sr & SR_RDF, 0, timeout_us);
> + if (ret)
> + return ret;
> + fsl_lpspi->rx(fsl_lpspi);
> + }
[Severity: High]
Will polling SR_RDF after transmitting a single word time out whenever
t->len >= 2?
fsl_lpspi_setup_transfer() sets fsl_lpspi->watermark to
min(fsl_lpspi->txfifosize, t->len), and fsl_lpspi_set_watermark() writes
FCR_RXWATER = fsl_lpspi->watermark >> 1 (>= 1 for t->len >= 2). In the
LPSPI controller, SR_RDF only asserts when the RX FIFO word count is
strictly greater than FCR_RXWATER. Because this loop only puts one word
in flight at a time, RXCOUNT reaches 1 and SR_RDF never asserts, so every
multi-byte transfer fails with -ETIMEDOUT. (The interrupt PIO path avoids
this in fsl_lpspi_read_rx_fifo() by checking RSR_RXEMPTY in IMX7ULP_RSR
instead of SR_RDF.)
> +
> + ret = readl_poll_timeout_atomic(fsl_lpspi->base + IMX7ULP_SR, sr,
> + sr & SR_TCF, 0, timeout_us);
> + if (ret)
> + return ret;
[Severity: High]
Can SR_TCF assert here while continuous transfer mode (TCR_CONT) is still
active?
Because fsl_lpspi->usedma is false, fsl_lpspi_set_cmd() sets TCR_CONT in
IMX7ULP_TCR, which keeps the transfer active after the TX FIFO drains
until a new command word without TCR_CONTC is written to IMX7ULP_TCR (as
fsl_lpspi_write_tx_fifo() and fsl_lpspi_isr() do before waiting for
SR_FCF). Without terminating the continuous command in IMX7ULP_TCR, this
poll on SR_TCF stalls for timeout_us and returns -ETIMEDOUT.
> +
> + writel(SR_TCF, fsl_lpspi->base + IMX7ULP_SR);
> + return 0;
> +}
> +
> +static int fsl_lpspi_transfer_atomic(struct spi_device *spi,
> + struct spi_message *msg)
> +{
> + struct spi_controller *controller = spi->controller;
> + struct fsl_lpspi_data *fsl_lpspi =
> + spi_controller_get_devdata(controller);
> + struct spi_transfer *t, *next;
> + bool first = true;
> + bool keep_cs = false;
> + int ret = 0;
> +
> + if (!pm_runtime_active(fsl_lpspi->dev))
> + return -ESHUTDOWN;
> +
> + fsl_lpspi->usedma = false;
> + fsl_lpspi_reset(fsl_lpspi);
> + writel(0, fsl_lpspi->base + IMX7ULP_DER);
> +
> + t = list_first_entry(&msg->transfers, struct spi_transfer, transfer_list);
> + spi_set_cs(spi, !t->cs_off, false);
[Severity: Medium]
Does asserting chip select before fsl_lpspi_setup_transfer() and
fsl_lpspi_set_cmd() glitch SCLK while CS is active?
In the normal path, fsl_lpspi_prepare_message() programs TCR_CPOL and
TCR_CPHA before the core asserts CS (see 7ae4d097b752 ("spi:
spi-fsl-lpspi: Handle clock polarity and phase")). __spi_sync_atomic()
does not call prepare_message(), so asserting CS right after
fsl_lpspi_reset() causes any clock polarity transition to happen while the
target device is already selected.
> +
> + list_for_each_entry(t, &msg->transfers, transfer_list) {
> + if (t->len) {
> + fsl_lpspi->is_first_byte = first;
> + ret = fsl_lpspi_setup_transfer(controller, spi, t, true);
> + if (ret)
> + break;
> + if (t->len %
> + fsl_lpspi_bytes_per_word(fsl_lpspi->config.bpw)) {
> + ret = -EINVAL;
> + break;
> + }
[Severity: Medium]
Does this length check reject valid 17..24 bits-per-word transfers?
For 17 <= bpw <= 24, __spi_validate() and fsl_lpspi_buf_tx_u32() /
fsl_lpspi_buf_rx_u32() use a 4-byte (sizeof(u32)) stride in memory,
whereas fsl_lpspi_bytes_per_word(bpw) returns DIV_ROUND_UP(bpw, 8) == 3.
A 17..24-bit transfer whose byte length is a multiple of 4 (such as 4 or 8
bytes) will fail here with -EINVAL.
> +
> + fsl_lpspi_set_cmd(fsl_lpspi);
> + fsl_lpspi->is_first_byte = false;
> +
> + ret = fsl_lpspi_pio_xfer_atomic(fsl_lpspi, t);
> + if (ret)
> + break;
> +
> + fsl_lpspi_reset(fsl_lpspi);
> + first = false;
> + }
[Severity: High]
Does calling fsl_lpspi_reset() at the end of each transfer break
subsequent transfers in a multi-transfer message?
fsl_lpspi_reset() clears CR_MEN and flushes the TX and RX FIFOs,
destroying any active continuous transfer state in the hardware (and
deasserting native PCS if GPIO CS is not used). Setting first = false
then causes the next transfer's fsl_lpspi_set_cmd() to write TCR_CONTC = 1
to a freshly reset controller with no active TCR_CONT command, which sets
the Transmit Error Flag (SR[TEF]) and drops the command.
> +
> + spi_transfer_delay_exec(t);
> +
> + if (t->cs_change) {
> + if (list_is_last(&t->transfer_list, &msg->transfers)) {
> + keep_cs = true;
> + } else {
> + if (!t->cs_off)
> + spi_set_cs(spi, false, false);
> + spi_transfer_cs_change_delay_exec(msg, t);
> + next = list_next_entry(t, transfer_list);
> + if (!next->cs_off)
> + spi_set_cs(spi, true, false);
> + }
> + } else if (!list_is_last(&t->transfer_list, &msg->transfers)) {
> + next = list_next_entry(t, transfer_list);
> + if (t->cs_off != next->cs_off)
> + spi_set_cs(spi, !next->cs_off, false);
> + }
> + }
> +
> + if (!keep_cs)
> + spi_set_cs(spi, false, false);
> + fsl_lpspi_reset(fsl_lpspi);
> + msg->status = ret;
> + return ret;
> +}
[Severity: Medium]
Should fsl_lpspi_transfer_atomic() update msg->actual_length and
t->effective_speed_hz?
__spi_sync_atomic() calls controller->transfer_atomic() directly without
going through spi_transfer_one_message(), so leaving msg->actual_length
unupdated causes callers that check it (such as spi_mem_exec_op()) to
treat completed atomic transfers as failed. Populating
t->effective_speed_hz after fsl_lpspi_setup_transfer() (as
fsl_lpspi_transfer_one() does) is also needed for SPI_DELAY_UNIT_SCK
delays in spi_transfer_delay_exec() and
spi_transfer_cs_change_delay_exec().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127073454.351296-1-chunyuzhiqiang@yinhe.ht?part=1
next prev parent reply other threads:[~2026-11-27 7:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 7:34 [RFC PATCH v2 0/1] spi: fsl-lpspi: add atomic transfer support ChunYuZhiQiang
2026-11-27 7:34 ` [RFC PATCH v2 1/1] " ChunYuZhiQiang
2026-11-27 7:59 ` sashiko-bot [this message]
2026-11-27 20:49 ` Heiko Stübner
2026-11-28 4:25 ` RE:[RFC " chunyuzhiqiang
2026-11-27 12:50 ` [RFC PATCH v2 0/1] " Mark Brown
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-236849@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=chunyuzhiqiang@yinhe.ht \
--cc=imx@lists.linux.dev \
--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.