From: sashiko-bot@kernel.org
To: "Miquel Raynal" <miquel.raynal@bootlin.com>,
"Mark Brown" <broonie@kernel.org>,
"Liang Yang" <liang.yang@amlogic.com>,
"Feng Chen" <feng.chen@amlogic.com>,
"Xianwei Zhao" <xianwei.zhao@amlogic.com>,
"Han Xu" <han.xu@nxp.com>,
"Conor Dooley" <conor.dooley@microchip.com>,
"Valentina Fernandez" <valentina.fernandezalanis@microchip.com>,
"Daire McNamara" <daire.mcnamara@microchip.com>,
"Haibo Chen" <haibo.chen@nxp.com>,
"Jyan Chou" <jyanchou@realtek.com>,
"Yu-Chun Lin" <eleanor.lin@realtek.com>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
"Pratyush Yadav" <pratyush@kernel.org>,
"Michael Walle" <mwalle@kernel.org>,
"Takahiro Kuwano" <takahiro.kuwano@infineon.com>,
"Richard Weinberger" <richard@nod.at>,
"Vignesh Raghavendra" <vigneshr@ti.com>
Cc: "Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Alvin Zhou" <alvinzhou@mxic.com.tw>,
"Cheng Ming Lin" <chengminglin@mxic.com.tw>,
linux-amlogic@lists.infradead.org, imx@lists.linux.dev,
linux-stm32@st-md-mailman.stormreply.com,
linux-mtd@lists.infradead.org, Frank.Li@kernel.org,
neil.armstrong@linaro.org
Subject: Re: [PATCH RFC 09/16] spi: microchip-core-qspi: Consume dummy cycles directly
Date: Wed, 25 Nov 2026 18:06:50 +0000 [thread overview]
Message-ID: <sashiko-outbox-233905@kernel.org> (raw)
In-Reply-To: <20261125-macronix-upstreaming-spi-mem-cycles-v1-9-fd036402fd37@bootlin.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] spi: microchip-core-qspi: dummy_cycles drops dummy phase on
GPIO-CS fallback
- [Medium] spi: microchip-core-qspi: unchecked ncycles shift in
mchp_coreqspi_config_op()
--
commit 2317911309a9a0d90fc21347c53a3b7c2797fde4
Author: Miquel Raynal <miquel.raynal@bootlin.com>
spi: microchip-core-qspi: Consume dummy cycles directly
This commit advertises the dummy_cycles capability in
mchp_coreqspi_mem_caps and uses op->dummy.ncycles directly in
mchp_coreqspi_config_op() instead of converting op->dummy.nbytes.
> diff --git a/drivers/spi/spi-microchip-core-qspi.c b/drivers/spi/spi-microchip-core-qspi.c
> index c0ea65014d2ea..2fc1df7380620 100644
> --- a/drivers/spi/spi-microchip-core-qspi.c
> +++ b/drivers/spi/spi-microchip-core-qspi.c
> @@ -420,7 +420,6 @@ static int mchp_coreqspi_setup_clock(struct mchp_coreqspi *qspi, struct spi_devi
>
> static void mchp_coreqspi_config_op(struct mchp_coreqspi *qspi, const struct spi_mem_op *op)
> {
> - u32 idle_cycles = 0;
> int total_bytes, cmd_bytes, frames, ctrl;
>
> cmd_bytes = op->cmd.nbytes + op->addr.nbytes;
> @@ -459,11 +458,7 @@ static void mchp_coreqspi_config_op(struct mchp_coreqspi *qspi, const struct spi
> writel_relaxed(frames, qspi->regs + REG_FRAMESUP);
> frames = total_bytes & BYTESLOWER_MASK;
> frames |= cmd_bytes << FRAMES_CMDBYTES_SHIFT;
> -
> - if (op->dummy.buswidth)
> - idle_cycles = op->dummy.nbytes * 8 / op->dummy.buswidth;
> -
> - frames |= idle_cycles << FRAMES_IDLE_SHIFT;
> + frames |= op->dummy.ncycles << FRAMES_IDLE_SHIFT;
[Severity: Medium]
Can op->dummy.ncycles << FRAMES_IDLE_SHIFT overflow the 4-bit
FRAMES_IDLE_MASK field in REG_FRAMES?
drivers/spi/spi-microchip-core-qspi.c:
#define FRAMES_IDLE_MASK GENMASK(29, 26)
#define FRAMES_IDLE_SHIFT 26
#define FRAMES_FLAGBYTE BIT(30)
#define FRAMES_FLAGWORD BIT(31)
mchp_coreqspi_supports_op() does not reject op->dummy.ncycles > 15.
When a flash operation requests more than 15 dummy cycles (such as SFDP
BFPT read modes with 16 or 20 cycles), shifting u8 op->dummy.ncycles (as a
signed int) by 26 overflows into FRAMES_FLAGBYTE and FRAMES_FLAGWORD (and
is undefined behavior when ncycles >= 32), while truncating the programmed
idle cycles to op->dummy.ncycles & 0xf.
Should mchp_coreqspi_supports_op() reject op->dummy.ncycles > 15?
> ctrl = readl_relaxed(qspi->regs + REG_CONTROL);
>
> if (ctrl & CONTROL_MODE12_MASK)
> @@ -601,6 +596,7 @@ static const struct spi_controller_mem_ops mchp_coreqspi_mem_ops = {
>
> static const struct spi_controller_mem_caps mchp_coreqspi_mem_caps = {
> .per_op_freq = true,
> + .dummy_cycles = true,
> };
[Severity: High]
Does setting .dummy_cycles = true drop the dummy phase when a SPI memory
device uses a GPIO chip-select?
mchp_coreqspi_probe() sets ctlr->use_gpio_descriptors = true. In
spi_mem_exec_op(), spi_mem_convert_dummy() runs before the
!spi_get_csgpiod(mem->spi, 0) check:
drivers/spi/spi-mem.c:spi_mem_exec_op() {
...
spi_mem_convert_dummy(mem, op);
...
if (ctlr->mem_ops && ctlr->mem_ops->exec_op && !spi_get_csgpiod(mem->spi, 0)) {
...
if (op->dummy.nbytes) {
memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes);
xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1;
xfers[xferpos].len = op->dummy.nbytes;
...
}
With .dummy_cycles = true, spi_mem_convert_dummy() stores the dummy phase
in op->dummy.ncycles and sets op->dummy.nbytes = 0. When a GPIO CS is
used, spi_mem_exec_op() falls back to spi_sync(), which only creates a
dummy transfer when op->dummy.nbytes is non-zero, while
mchp_coreqspi_prepare_message() hardcodes idle_cycles = 0. As a result,
no dummy cycles are transmitted on the bus, corrupting flash reads on
boards with GPIO chip-selects.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-macronix-upstreaming-spi-mem-cycles-v1-0-fd036402fd37@bootlin.com?part=9
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
next prev parent reply other threads:[~2026-11-25 18:06 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 17:51 [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 01/16] spi: spi-mem: Handle a corner case while sanitizing ops Miquel Raynal
2026-11-25 17:58 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 02/16] spi: spi-mem: Stop checking the dummy buswidth against board wiring Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 03/16] spi: spi-mem: Add support for dummy cycles Miquel Raynal
2026-11-25 18:07 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 04/16] spi: amlogic-spifc-a1: Consume dummy cycles directly Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 05/16] spi: amlogic-spifc-a1: Fix a typo in a macro Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 06/16] spi: amlogic: spifc-a4: Consume dummy cycles directly Miquel Raynal
2026-11-25 17:59 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 07/16] spi: cadence-qspi: " Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 08/16] spi: fsl-qspi: " Miquel Raynal
2026-11-25 17:58 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 09/16] spi: microchip-core-qspi: " Miquel Raynal
2026-11-25 18:06 ` sashiko-bot [this message]
2026-11-25 17:51 ` [PATCH RFC 10/16] spi: nxp-xspi: " Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 11/16] spi: nxp-xspi: Fix a comment Miquel Raynal
2026-11-25 17:51 ` [PATCH RFC 12/16] spi: rtk-nor: Consume dummy cycles directly Miquel Raynal
2026-11-25 18:02 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 13/16] spi: sn-f-ospi: " Miquel Raynal
2026-11-25 18:01 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 14/16] spi: stm32-ospi: " Miquel Raynal
2026-11-25 18:12 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 15/16] spi: stm32-qspi: " Miquel Raynal
2026-11-25 18:14 ` sashiko-bot
2026-11-25 17:51 ` [PATCH RFC 16/16] mtd: spi-nor: Express the dummy phase in cycles Miquel Raynal
2026-11-25 18:08 ` sashiko-bot
2026-11-26 11:09 ` [PATCH RFC 00/16] spi: spi-mem: Express the dummy phase using cycles when relevant Miquel Raynal
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-233905@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=alexandre.torgue@foss.st.com \
--cc=alvinzhou@mxic.com.tw \
--cc=broonie@kernel.org \
--cc=chengminglin@mxic.com.tw \
--cc=conor.dooley@microchip.com \
--cc=daire.mcnamara@microchip.com \
--cc=eleanor.lin@realtek.com \
--cc=feng.chen@amlogic.com \
--cc=haibo.chen@nxp.com \
--cc=han.xu@nxp.com \
--cc=imx@lists.linux.dev \
--cc=jyanchou@realtek.com \
--cc=liang.yang@amlogic.com \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=miquel.raynal@bootlin.com \
--cc=mwalle@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=pratyush@kernel.org \
--cc=richard@nod.at \
--cc=sashiko-reviews@lists.linux.dev \
--cc=takahiro.kuwano@infineon.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=valentina.fernandezalanis@microchip.com \
--cc=vigneshr@ti.com \
--cc=xianwei.zhao@amlogic.com \
/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