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 04/11] spi: dw: add check for support of enhanced spi
Date: Thu, 09 Jul 2026 14:13:36 +0000 [thread overview]
Message-ID: <20260709141336.E109C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260709055204.138168-5-changhuang.liang@starfivetech.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The dummy cycle check uses integer division incorrectly, allowing wait cycle configurations that silently overflow the 5-bit hardware wait cycle register.
- [High] The buswidth validation logic incorrectly rejects valid NO_DATA operations (e.g., QPI Erase) while accepting unsupported mixed-buswidth operations (e.g., 4-1-4).
--
--- Patch [4]: [PATCH v1 04/11] spi: dw: add check for support of enhanced spi ---
commit fe456b0bd9838cdf376b52d9ec69265dbf1ef090
Author: Sudip Mukherjee <sudip.mukherjee@sifive.com>
spi: dw: add check for support of enhanced spi
This commit queries the spi controller for buswidths it supports before doing
a mem op. It adds dual/quad/octal mode checks if the controller has the
DW_SPI_CAP_EMODE capability.
> diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c
> index 6befe47929b4c..010a665b17b76 100644
> --- a/drivers/spi/spi-dw-core.c
> +++ b/drivers/spi/spi-dw-core.c
> @@ -521,6 +521,32 @@ static int dw_spi_adjust_mem_op_size(struct spi_mem *mem, struct spi_mem_op *op)
> return 0;
> }
>
> +static bool dw_spi_supports_enh_mem_op(struct spi_mem *mem,
> + const struct spi_mem_op *op)
> +{
> + if (op->addr.nbytes != 0 && op->addr.buswidth != 1 &&
> + op->addr.buswidth != op->data.buswidth)
> + return false;
[Severity: High]
Does this logic incorrectly reject valid operations that have no data phase,
like Quad SPI Erase?
If an operation has no data phase (op->data.nbytes == 0), the SPI core
initializes op->data.buswidth to 0. For an erase command over QSPI
(e.g., 1-4-0), op->addr.buswidth != op->data.buswidth evaluates to 4 != 0,
which erroneously returns false.
> +
> + if (op->addr.nbytes >= 8)
> + return false;
> +
> + if (op->cmd.buswidth != 1 && op->cmd.buswidth != op->addr.buswidth &&
> + op->cmd.buswidth != op->data.buswidth)
> + return false;
[Severity: High]
Can this logical AND chain accidentally accept unsupported configurations?
For an operation like 4-1-4, op->cmd.buswidth != op->data.buswidth evaluates
as 4 != 4 (false), which short-circuits the AND chain and bypasses the
rejection.
> +
> + if (op->dummy.nbytes && !op->dummy.buswidth)
> + return false;
> +
> + if (op->dummy.nbytes != 0 && op->data.dir == SPI_MEM_DATA_OUT)
> + return false;
> +
> + if (op->dummy.nbytes != 0 && op->dummy.nbytes / op->dummy.buswidth > 4)
> + return false;
[Severity: High]
Does this integer division silently allow configurations that overflow the
5-bit hardware wait cycle register?
Due to truncation, a configuration with op->dummy.nbytes = 19 and
op->dummy.buswidth = 4 will evaluate as 4 > 4 (false) and be accepted.
This corresponds to 38 SPI clocks ((19 * 8) / 4). Since the hardware wait
cycle register (DW_SPI_ENH_CTRLR0_WAIT_CYCLE_MASK) has a maximum limit of
31 cycles, programming 38 will be bitwise-ANDed by FIELD_PREP() to 6 cycles.
This could result in sampling data out of sync and corrupting the read.
> +
> + return spi_mem_default_supports_op(mem, op);
> +}
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260709055204.138168-1-changhuang.liang@starfivetech.com?part=4
next prev parent reply other threads:[~2026-07-09 14:13 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 [this message]
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
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=20260709141336.E109C1F000E9@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 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.