From: sashiko-bot@kernel.org
To: "Changhuang Liang" <changhuang.liang@starfivetech.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v1 09/11] spi: dw: detect enhanced spi mode
Date: Thu, 09 Jul 2026 15:20:00 +0000 [thread overview]
Message-ID: <20260709152000.B1D1E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260709055204.138168-10-changhuang.liang@starfivetech.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] detect_enh_mode() leaks detected multi-lane modes into ctlr->mode_bits on clock stretch test failure.
- [High] Advertising multi-bit SPI modes globally without supporting them in dw_spi_transfer_one() causes standard multi-lane transfers to corrupt data.
- [High] The register writability test falsely detects OCTAL mode support on QUAD-only hardware.
- [High] dw_spi_hw_init() blindly overwrites ctlr->mode_bits, wiping out dynamically established capabilities like SPI_LOOP after a suspend/resume cycle.
--
--- Patch [9]: [PATCH v1 09/11] spi: dw: detect enhanced spi mode ---
commit 0f885f7a3380b812c7026e7502b6a3b2baf64278
Author: Sudip Mukherjee <sudip.mukherjee@sifive.com>
spi: dw: detect enhanced spi mode
All the SSI controllers supporting enhanced spi modes might not support
all the three dual or quad or octal modes. Detect the modes that are
supported and finally enable the DW_SPI_CAP_EMODE capability which will
start using all the enhanced spi functions that has been added.
> diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c
> index 526b54385cd3e..ef1abb540f069 100644
> --- a/drivers/spi/spi-dw-core.c
> +++ b/drivers/spi/spi-dw-core.c
[ ... ]
> @@ -1083,6 +1083,64 @@ static void dw_spi_cleanup(struct spi_device *spi)
[ ... ]
> +static u16 detect_enh_mode(struct dw_spi *dws)
> +{
[ ... ]
> + /* test octal mode */
> + tmp_val = DW_SPI_CTRLR0_SPI_FRF_OCT_SPI << frf_shift;
> + dw_writel(dws, DW_SPI_CTRLR0, tmp_val);
> + if ((tmp_val & dw_readl(dws, DW_SPI_CTRLR0)) == tmp_val)
> + mode |= SPI_TX_OCTAL | SPI_RX_OCTAL;
[Severity: High]
Can this writability test falsely detect Octal mode support on Quad-only
hardware?
If the SPI_FRF field is 2 bits wide, Quad mode would require both physical
flip-flops to exist. When the driver tests for Octal mode by writing a value
that sets both bits, the readback will confirm both bits are set. This would
hold the value and trick the driver into assuming the IP supports internal
Octal logic when it may only be synthesized for Quad.
> +
> + if (!mode)
> + goto disable_enh;
> +
> + /* test clock stretching */
> + dw_writel(dws, DW_SPI_SPI_CTRLR0, DW_SPI_ENH_CTRLR0_CLK_STRETCH_EN);
> + if ((DW_SPI_ENH_CTRLR0_CLK_STRETCH_EN & dw_readl(dws, DW_SPI_SPI_CTRLR0)) !=
> + DW_SPI_ENH_CTRLR0_CLK_STRETCH_EN)
> + /*
> + * If clock stretching is not enabled then do not use
> + * enhanced mode.
> + */
> + goto disable_enh;
[Severity: High]
Does this error path leak the detected multi-lane modes?
When the clock stretching test fails, the code jumps to the disable_enh label
without clearing the local mode variable. The non-zero mode bitmask is then
returned and unconditionally bitwise-ORed into ctlr->mode_bits by the caller.
Could this falsely advertise multi-lane capabilities to the SPI subsystem
when the controller does not actually support enhanced mode?
> +
> + dws->caps |= DW_SPI_CAP_EMODE;
> +
> +disable_enh:
> + dw_writel(dws, DW_SPI_CTRLR0, tmp_ctrlr0);
> + dw_writel(dws, DW_SPI_SPI_CTRLR0, tmp_spi_ctrlr0);
> + dw_spi_enable_chip(dws, 1);
> +
> + return mode;
> +}
[ ... ]
> @@ -1162,6 +1220,9 @@ static void dw_spi_hw_init(struct device *dev, struct dw_spi *dws)
[ ... ]
> dws->caps |= DW_SPI_CAP_DFS32;
> }
>
> + dws->ctlr->mode_bits = SPI_CPOL | SPI_CPHA;
[Severity: High]
Does this direct assignment overwrite dynamically established capabilities?
During initial probe, dw_spi_add_controller() sets capabilities like:
ctlr->mode_bits |= SPI_LOOP;
When the system resumes, dw_spi_resume_controller() calls dw_spi_hw_init():
drivers/spi/spi-dw-core.c:dw_spi_resume_controller() {
...
dw_spi_hw_init(&dws->ctlr->dev, dws);
...
}
Will this blind assignment wipe out flags like SPI_LOOP after a
suspend/resume cycle?
> + dws->ctlr->mode_bits |= detect_enh_mode(dws);
[Severity: High]
Does advertising these multi-bit SPI modes globally cause standard multi-lane
transfers to corrupt data?
By adding these multi-lane modes to the controller's mode_bits, they are
exposed to standard (non-mem_ops) SPI transfers. If a user-space application
or kernel driver initiates a standard spi_transfer with tx_nbits > 1, the SPI
core will accept it.
However, looking at dw_spi_transfer_one(), the standard transfer handler
appears to ignore multi-lane requests and executes everything in 1-bit
standard mode:
drivers/spi/spi-dw-core.c:dw_spi_transfer_one() {
...
.spi_frf = DW_SPI_CTRLR0_SPI_FRF_STD_SPI,
...
}
Will this result in data corruption and protocol mismatch on the SPI bus?
> +
> /* enable HW fixup for explicit CS deselect for Amazon's alpine chip */
> if (dws->caps & DW_SPI_CAP_CS_OVERRIDE)
> dw_writel(dws, DW_SPI_CS_OVERRIDE, 0xF);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260709055204.138168-1-changhuang.liang@starfivetech.com?part=9
next prev parent reply other threads:[~2026-07-09 15:20 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 5:51 [PATCH v1 00/11] Add support for StarFive JHB100 SFC Changhuang Liang
2026-07-09 5:51 ` [PATCH v1 01/11] spi: dw: Introduce spi_frf and STD_SPI Changhuang Liang
2026-07-09 5:51 ` [PATCH v1 02/11] spi: dw: update NDF while using enhanced spi mode Changhuang Liang
2026-07-09 13:50 ` sashiko-bot
2026-07-09 5:51 ` [PATCH v1 03/11] spi: dw: update SPI_CTRLR0 register Changhuang Liang
2026-07-09 14:00 ` sashiko-bot
2026-07-09 5:51 ` [PATCH v1 04/11] spi: dw: add check for support of enhanced spi Changhuang Liang
2026-07-09 14:13 ` sashiko-bot
2026-07-09 5:51 ` [PATCH v1 05/11] spi: dw: Introduce enhanced single/dual/quad/octal spi Changhuang Liang
2026-07-09 14:23 ` sashiko-bot
2026-07-09 5:51 ` [PATCH v1 06/11] spi: dw: send cmd and addr to start the spi transfer Changhuang Liang
2026-07-09 14:37 ` sashiko-bot
2026-07-09 5:52 ` [PATCH v1 07/11] spi: dw: use irq handler for enhanced spi Changhuang Liang
2026-07-09 14:50 ` sashiko-bot
2026-07-09 5:52 ` [PATCH v1 08/11] spi: dw: adjust size of mem_op Changhuang Liang
2026-07-09 15:08 ` sashiko-bot
2026-07-09 5:52 ` [PATCH v1 09/11] spi: dw: detect enhanced spi mode Changhuang Liang
2026-07-09 15:20 ` sashiko-bot [this message]
2026-07-09 5:52 ` [PATCH v1 10/11] spi: dt-bindings: snps,dw-apb-ssi: Add starfive,jhb100-sfc Changhuang Liang
2026-07-09 17:55 ` Conor Dooley
2026-07-09 5:52 ` [PATCH v1 11/11] spi: dw: Add support for StarFive JHB100 SoC SFC Changhuang Liang
2026-07-09 15:34 ` 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=20260709152000.B1D1E1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=changhuang.liang@starfivetech.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox