From: sashiko-bot@kernel.org
To: "Prakriti Sharma" <Prakriti.Sharma@synopsys.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 2/5] spi: dw-g2: Add support for Synopsys DWC SSI v2.02a controller
Date: Mon, 30 Nov 2026 03:01:42 +0000 [thread overview]
Message-ID: <sashiko-outbox-240281@kernel.org> (raw)
In-Reply-To: <8c1c5762858dd88b23e4b73dd28913f495ff7580.1795683279.git.prakriti@synopsys.com>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] spi: dw-g2: premature transfer abort in dw_spi_g2_cmd_only()
and wait_idle()
- [High] spi: dw-g2: missing ctlr->handle_err leaves IRQ transfer active
on timeout
- [High] spi: dw-g2: unlocked concurrent execution of dw_spi_g2_irq()
across IRQs
- [Medium] spi: dw-g2: missing SPI_CPOL and SPI_CPHA setup in
dw_spi_g2_build_ctrlr0()
- [Medium] spi: dw-g2: missing ctlr->max_speed_hz setup in
dw_spi_g2_init()
- [Medium] spi: dw-g2: missing ctlr->max_speed_hz and clobbered caps in
dw_spi_g2_init()
- [Low] spi: dw-g2: redundant TXEI interrupt on short transfers in
dw_spi_g2_transfer_one()
--
commit 164e383f9dc370e3fcd8dcc242bc57e332d6ec75
Author: Prakriti Sharma <Prakriti.Sharma@synopsys.com>
spi: dw-g2: Add support for Synopsys DWC SSI v2.02a controller
This commit introduces a platform driver for the Synopsys DesignWare SSI
Gen2 (v2.02a) MMIO SPI controller with interrupt-driven standard transfers
and spi-mem command-only and short register operations.
> diff --git a/drivers/spi/spi-dw-g2-core.c b/drivers/spi/spi-dw-g2-core.c
> new file mode 100644
> index 0000000000000..b2a3e3e8670eb
> --- /dev/null
> +++ b/drivers/spi/spi-dw-g2-core.c
> @@ -0,0 +1,925 @@
[ ... ]
> +static u32 dw_spi_g2_build_ctrlr0(struct dw_spi_g2 *dws, u8 tmod, u8 frf)
> +{
[ ... ]
> + ctrlr0 |=
> + FIELD_PREP(DW_SPI_G2_CTRLR0_DFS_MASK, DW_SPI_G2_DFS_ENCODE(dfs));
> + ctrlr0 |= FIELD_PREP(DW_SPI_G2_CTRLR0_TMOD_MASK, tmod);
> + ctrlr0 |= FIELD_PREP(DW_SPI_G2_CTRLR0_FRF_MASK, frf);
> +
> + return ctrlr0;
> +}
[Severity: Medium]
Should dw_spi_g2_build_ctrlr0() also encode DW_SPI_G2_CTRLR0_SCPOL and
DW_SPI_G2_CTRLR0_SCPHA from dws->curr_spi->mode?
dw_spi_g2_transfer_one() ORs those bits in after calling
dw_spi_g2_build_ctrlr0(), but dw_spi_g2_cmd_only_setup() and
dw_spi_g2_reg_op_setup() write the return value directly to
DW_SPI_G2_CTRLR0(dws->cs). Any spi-mem flash device configured for SPI
Mode 1, 2, or 3 will have its transactions clocked in Mode 0.
[ ... ]
> +static int dw_spi_g2_cmd_only(struct dw_spi_g2 *dws,
> + const struct spi_mem_op *op)
> +{
[ ... ]
> + for (i = 0; i < len; i++)
> + dw_spi_g2_writel(dws->regs, DW_SPI_G2_DR0, buf[i]);
> +
> + dw_spi_g2_cs_assert(dws, dws->cs);
> + ret = dw_spi_g2_wait_idle(dws);
> +
> + dw_spi_g2_transfer_end(dws);
> + dw_spi_g2_controller_reset(dws);
> +
> + return ret;
> +}
[Severity: High]
Can dw_spi_g2_wait_idle() return before the TX FIFO starts shifting out,
causing dw_spi_g2_transfer_end() to abort the command?
dw_spi_g2_wait_idle() only checks !(sr & DW_SPI_G2_SR_BUSY):
drivers/spi/spi-dw-g2.h:dw_spi_g2_wait_idle() {
u32 sr;
return readl_poll_timeout(dws->regs + DW_SPI_G2_SR, sr,
!(sr & DW_SPI_G2_SR_BUSY), 1, DW_SPI_G2_TIMEOUT_US);
}
As the comment in dw_spi_g2_reg_op() notes for the same prefill and CS
assertion pattern, polling only !DW_SPI_G2_SR_BUSY without
DW_SPI_G2_SR_TFE can return early before DW_SPI_G2_SER propagates into the
ssi_clk domain. When that happens in dw_spi_g2_cmd_only() or
dw_spi_g2_xfer_fifo(), disabling SSIENR and deasserting CS flushes the
queued bytes from the TX FIFO and drops the SPI command.
[ ... ]
> +static int dw_spi_g2_transfer_one(struct spi_controller *ctlr,
> + struct spi_device *spi,
> + struct spi_transfer *xfer)
> +{
[ ... ]
> + dw_spi_g2_writel(dws->regs, DW_SPI_G2_CTRLR0(dws->cs), ctrlr0);
> + dw_spi_g2_writel(dws->regs, DW_SPI_G2_CTRLR1(dws->cs), 0);
> + dw_spi_g2_writel(dws->regs, DW_SPI_G2_SPI_CTRLR0(dws->cs), 0);
> + dw_spi_g2_writel(dws->regs, DW_SPI_G2_BAUDR(dws->cs),
> + dw_spi_g2_baudr(dws, xfer->speed_hz));
[Severity: Medium]
Can xfer->speed_hz be 0 here when a device relies on the controller's
default maximum speed?
Because dw_spi_g2_init() does not set ctlr->max_speed_hz = dws->max_freq,
the SPI core leaves spi->max_speed_hz and xfer->speed_hz at 0 when a
peripheral does not specify a maximum frequency (and does not clamp higher
speeds to dws->max_freq). dw_spi_g2_baudr(dws, 0) then returns
DW_SPI_G2_MAX_BAUDR (65534), dropping the bus clock to its slowest
possible divider instead of dws->max_freq. In addition,
dw_spi_g2_mmio_probe() calls of_alias_get_id(pdev->dev.of_node, "spi"),
which is undocumented in the DT binding and already handled by
spi_register_controller().
> +
> + dw_spi_g2_target_enable(dws, dws->cs);
> + dw_spi_g2_enable(dws, true);
> +
> + /* Ensure irq_xfer is visible before unmasking TXEI/RXFI. */
> + smp_wmb();
> + dws->irq_xfer = true;
> +
> + dw_spi_g2_irq_xfer_setup(dws);
> + dw_spi_g2_irq_writer(dws);
> + dw_spi_g2_umask_intr(dws, DW_SPI_G2_IMR_XFER_ERR);
[Severity: Low]
Does unmasking DW_SPI_G2_ISR_TXEI unconditionally after
dw_spi_g2_irq_writer() trigger an extra interrupt on every transfer that
fits in the TX FIFO?
When xfer->len <= dws->fifo_len, dw_spi_g2_irq_writer() pushes the entire
transfer into the TX FIFO and decrements dws->irq_tx_rem to 0 before
interrupts are unmasked. Unmasking DW_SPI_G2_ISR_TXEI anyway causes a
TXEI interrupt to fire only for dw_spi_g2_irq() to see !dws->irq_tx_rem
and mask DW_SPI_G2_ISR_TXEI.
[ ... ]
> +int dw_spi_g2_init(struct dw_spi_g2 *dws)
> +{
[ ... ]
> + dws->fifo_len = dw_spi_g2_detect_fifo_len(dws);
> + dws->caps = 0;
> +
> + if (!dws->max_freq)
> + dws->max_freq = DW_SPI_G2_DEF_MAX_FREQ;
[Severity: Medium]
Does dw_spi_g2_init() clobber dws->caps and leave ctlr->max_speed_hz
unset?
dw_spi_g2_mmio_probe() reads DW_SPI_G2_HW_CAPABILITIES into
dws->caps = dws->hw_caps and programs DW_SPI_G2_DEDICATED_CS_EN right
before calling dw_spi_g2_init(), which zeroes both DW_SPI_G2_DEDICATED_CS_EN
and dws->caps. Also, ctlr->max_speed_hz is never initialized from
dws->max_freq, so transfers without an explicit speed fall back to
dw_spi_g2_baudr(dws, 0) (DW_SPI_G2_MAX_BAUDR) in dw_spi_g2_transfer_one()
and override the baud rate programmed by dw_spi_g2_setup().
> +
> + ctlr->mode_bits = SPI_CPOL | SPI_CPHA |
> + SPI_TX_DUAL | SPI_RX_DUAL |
> + SPI_TX_QUAD | SPI_RX_QUAD | SPI_TX_OCTAL | SPI_RX_OCTAL;
> +
> + ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
> + ctlr->flags = 0;
> +
> + ctlr->setup = dw_spi_g2_setup;
> + ctlr->set_cs = dw_spi_g2_set_cs;
> + ctlr->transfer_one = dw_spi_g2_transfer_one;
> + ctlr->mem_ops = &dw_spi_g2_mem_ops;
[Severity: High]
What stops the in-flight IRQ transfer if spi_transfer_wait() times out?
Without a ctlr->handle_err callback to mask interrupts, clear
dws->irq_xfer, and disable the controller, a timed-out message is
finalized by the SPI core while DW_SPI_G2_IMR_XFER_ERR remains unmasked
and dws->irq_tx / dws->irq_rx still point to the caller's transfer
buffers:
CPU0 CPU1
spi_transfer_one_message()
dw_spi_g2_transfer_one()
dws->irq_rx = xfer->rx_buf
dws->irq_xfer = true
dw_spi_g2_umask_intr(...)
spi_transfer_wait() -> -ETIMEDOUT
spi_finalize_current_message()
/* caller frees xfer->rx_buf */
<hardirq>
dw_spi_g2_irq()
dw_spi_g2_irq_reader()
dws->irq_rx[idx] = val <-- use-after-free
In addition, if a threshold interrupt fires in dw_spi_g2_irq() while
!dws->irq_xfer, returning IRQ_NONE without masking DW_SPI_G2_IMR leaves
the level-triggered interrupt asserted.
> diff --git a/drivers/spi/spi-dw-g2-mmio.c b/drivers/spi/spi-dw-g2-mmio.c
> new file mode 100644
> index 0000000000000..1be68c4250e67
> --- /dev/null
> +++ b/drivers/spi/spi-dw-g2-mmio.c
> @@ -0,0 +1,168 @@
[ ... ]
> + static const char * const irq_names[] = {
> + "rxf", "txe", "txaf", "wsf",
> + };
> + bool any_named = false;
> +
> + for (i = 0; i < ARRAY_SIZE(irq_names); i++) {
> + irq = platform_get_irq_byname_optional(pdev, irq_names[i]);
> + if (irq < 0)
> + continue;
> +
> + ret = devm_request_irq(dev, irq, dw_spi_g2_irq, 0,
> + dev_name(dev), dws);
[Severity: High]
When the platform wires separate IRQ lines for "rxf" and "txe", can
dw_spi_g2_irq() run concurrently on two CPUs without locking?
Distinct IRQ numbers are not serialized against each other, and
dw_spi_g2_transfer_one() unmasks both DW_SPI_G2_ISR_RXFI and
DW_SPI_G2_ISR_TXEI:
CPU0 (IRQ "rxf") CPU1 (IRQ "txe")
dw_spi_g2_irq() dw_spi_g2_irq()
dw_spi_g2_irq_reader() dw_spi_g2_irq_reader()
max = dw_spi_g2_irq_rx_max() max = dw_spi_g2_irq_rx_max()
idx = irq_len - irq_rx_rem idx = irq_len - irq_rx_rem
readl(DW_SPI_G2_DR0) readl(DW_SPI_G2_DR0)
irq_rx[idx] = val irq_rx[idx] = val
irq_rx_rem-- irq_rx_rem-- <-- u32 underflow / OOB write
Both handlers also race on dw_spi_g2_irq_writer(), read-modify-write
updates to DW_SPI_G2_IMR, and dw_spi_g2_irq_finalize(), and if the first
CPU drains the FIFO before the second CPU reads DW_SPI_G2_ISR, the second
handler sees isr == 0 and returns IRQ_NONE.
Also, in dw_spi_g2_transfer_one(), smp_wmb() is placed before
dws->irq_xfer = true rather than between dws->irq_xfer = true and
dw_spi_g2_umask_intr(), and "if (irq < 0) continue;" here silently drops
-EPROBE_DEFER from platform_get_irq_byname_optional().
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795683279.git.prakriti@synopsys.com?part=2
next prev parent reply other threads:[~2026-11-30 3:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 2:39 [PATCH v2 0/5] spi: dw-g2: add Synopsys DWC SSI v2.02a controller support Prakriti Sharma
2026-11-30 2:39 ` [PATCH v2 1/5] spi: dt-bindings: snps,dwc-ssi-2.02a: Add DWC SSI v2.02a controller binding Prakriti Sharma
2026-11-30 2:47 ` sashiko-bot
2026-11-30 13:59 ` Rob Herring (Arm)
2026-11-30 16:41 ` Rob Herring
2026-11-30 2:39 ` [PATCH v2 2/5] spi: dw-g2: Add support for Synopsys DWC SSI v2.02a controller Prakriti Sharma
2026-11-30 3:01 ` sashiko-bot [this message]
2026-11-30 2:39 ` [PATCH v2 3/5] spi: dw-g2: Add support for indirect read and write for spi-mem transfers Prakriti Sharma
2026-11-30 3:03 ` sashiko-bot
2026-11-30 2:39 ` [PATCH v2 4/5] spi: dw-g2: Add support for SPI-NAND devices Prakriti Sharma
2026-11-30 2:59 ` sashiko-bot
2026-11-30 2:39 ` [PATCH v2 5/5] spi: dw-g2: Add support for memory-mapped XIP Prakriti Sharma
2026-11-30 3:09 ` 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-240281@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Prakriti.Sharma@synopsys.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@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.