From: sashiko-bot@kernel.org
To: "Santhosh Kumar K" <s-k6@ti.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v3 08/13] spi: cadence-quadspi: add PHY tuning support
Date: Wed, 27 May 2026 18:44:04 +0000 [thread overview]
Message-ID: <20260527184405.3E9741F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260527175527.2247679-9-s-k6@ti.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] The final search point calculation for dual-region DDR tuning lacks bounds clamping, causing integer underflow/overflow on u8 types.
- [High] Outer TX sweep loops unconditionally apply an extra step increment after a successful pattern check, corrupting the discovered TX coordinate.
- [High] The execute_tuning callback performs unlocked read-modify-write operations on shared controller registers, risking race conditions with concurrent SPI transfers.
- [High] cqspi_find_rx_high_sdr() incorrectly returns -ENOENT and aborts tuning if the valid RX window is exactly one tap wide.
--
commit 58d61a0f7bbd617a13de461da80be17236414b26
Author: Santhosh Kumar K <s-k6@ti.com>
spi: cadence-quadspi: add PHY tuning support
This commit adds an execute_tuning callback to perform delay-line PHY
calibration using a known data pattern. It performs either a 2D sweep for
DDR protocols or a 1D sweep for SDR protocols to find optimal delay points.
> diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
> index f4efb92c9446a..013fd50e416bd 100644
> --- a/drivers/spi/spi-cadence-quadspi.c
> +++ b/drivers/spi/spi-cadence-quadspi.c
[ ... ]
> @@ -1559,10 +1641,1687 @@ static bool cqspi_supports_mem_op(struct spi_mem *mem,
> return spi_mem_default_supports_op(mem, op);
> }
[ ... ]
> +static int cqspi_find_rx_high_sdr(struct cqspi_flash_pdata *f_pdata,
> + struct spi_mem *mem, struct phy_setting *phy,
> + u8 lowerbound)
> +{
> + struct device *dev = &f_pdata->cqspi->pdev->dev;
> + int ret;
> +
> + phy->rx = CQSPI_PHY_MAX_DELAY;
> + do {
> + ret = cqspi_phy_apply_setting(f_pdata, phy);
> + if (!ret) {
> + ret = cqspi_phy_check_pattern(f_pdata, mem);
> + if (!ret)
> + return 0;
> + }
> + phy->rx--;
> + } while (phy->rx > lowerbound);
> +
> + dev_dbg(dev, "Unable to find RX high\n");
> + return -ENOENT;
> +}
[Severity: High]
If the valid passing window is exactly 1 tap wide, no value strictly greater
than lowerbound will pass the pattern check. Would this loop decrement
phy->rx down to lowerbound and then exit returning -ENOENT? Since lowerbound
is already known to be a passing value, should this function instead
successfully return lowerbound to avoid aborting the SDR PHY tuning process?
[ ... ]
> + /* Primary rxlow: Sweep TX window to find valid RX lower bound */
> +
> + rxlow.tx = CQSPI_PHY_TX_LOOKUP_LOW_START;
> + do {
> + dev_dbg(dev, "Searching for Golden Primary rxlow on TX = %d\n",
> + rxlow.tx);
> + rxlow.read_delay = CQSPI_PHY_INIT_RD;
> + ret = cqspi_find_rx_low_ddr(f_pdata, mem, &rxlow);
> + rxlow.tx += CQSPI_PHY_DDR_SEARCH_STEP;
> + } while (ret && rxlow.tx <= CQSPI_PHY_TX_LOOKUP_LOW_END);
[Severity: High]
Does this unconditionally add CQSPI_PHY_DDR_SEARCH_STEP even if
cqspi_find_rx_low_ddr() returns success? If ret == 0, rxlow.tx gets
incremented right before the loop exits, which might shift the recorded tx
coordinate away from the actual successful coordinate.
[ ... ]
> + /* Compare Manhattan distances: choose corner furthest from gap */
> + if ((abs(gaplow.tx - bottomleft.tx) +
> + abs(gaplow.rx - bottomleft.rx)) <
> + (abs(gaphigh.tx - topright.tx) +
> + abs(gaphigh.rx - topright.rx))) {
> + /* Topright further: Use Region 2, 16 taps inward */
> + searchpoint = topright;
> + searchpoint.tx -= 16;
> + searchpoint.rx -= (16 * (topright.rx - bottomleft.rx)) /
> + (topright.tx - bottomleft.tx);
> + } else {
> + /* Bottomleft further: Use Region 1, 16 taps inward */
> + searchpoint = bottomleft;
> + searchpoint.tx += 16;
> + searchpoint.rx += (16 * (topright.rx - bottomleft.rx)) /
> + (topright.tx - bottomleft.tx);
> + }
[Severity: High]
Since searchpoint.tx and searchpoint.rx are u8 types, could subtracting 16
cause an underflow if topright.tx or topright.rx is less than 16? This
might result in wrapping around to a large positive value. Should these
calculations be clamped to ensure they stay within valid bounds?
[ ... ]
> +static int cqspi_am654_ospi_execute_tuning(struct spi_mem *mem,
> + struct spi_mem_op *read_op,
> + struct spi_mem_op *write_op)
> +{
> + struct cqspi_st *cqspi =
> + spi_controller_get_devdata(mem->spi->controller);
> + struct cqspi_flash_pdata *f_pdata;
[Severity: High]
Does execute_tuning() run without holding the SPI controller's bus lock
mutex? If so, could this race with concurrent SPI transfers from other devices
on the same controller, potentially causing issues when tuning functions like
cqspi_resync_dll() perform unlocked read-modify-write operations on shared
global registers like CQSPI_REG_CONFIG?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260527175527.2247679-1-s-k6@ti.com?part=8
next prev parent reply other threads:[~2026-05-27 18:44 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-27 17:55 [PATCH v3 00/13] spi: cadence-quadspi: add PHY tuning support Santhosh Kumar K
2026-05-27 17:55 ` [PATCH v3 01/13] spi: dt-bindings: allow spi-max-frequency to specify a frequency pair Santhosh Kumar K
2026-05-27 18:17 ` sashiko-bot
2026-05-28 8:32 ` Miquel Raynal
2026-05-28 17:36 ` Conor Dooley
2026-05-27 17:55 ` [PATCH v3 02/13] spi: dt-bindings: cdns,qspi-nor: add PHY tuning pattern partition property Santhosh Kumar K
2026-05-27 18:11 ` sashiko-bot
2026-05-28 8:34 ` Miquel Raynal
2026-05-27 17:55 ` [PATCH v3 03/13] spi: parse two-element spi-max-frequency property Santhosh Kumar K
2026-05-27 18:19 ` sashiko-bot
2026-05-28 8:37 ` Miquel Raynal
2026-05-27 17:55 ` [PATCH v3 04/13] spi: spi-mem: add spi_mem_apply_base_freq_cap() Santhosh Kumar K
2026-05-27 18:32 ` sashiko-bot
2026-05-28 8:43 ` Miquel Raynal
2026-05-27 17:55 ` [PATCH v3 05/13] spi: spi-mem: add execute_tuning callback and spi_mem_execute_tuning() Santhosh Kumar K
2026-05-27 18:21 ` sashiko-bot
2026-05-28 8:44 ` Miquel Raynal
2026-05-27 17:55 ` [PATCH v3 06/13] spi: cadence-quadspi: move cqspi_readdata_capture earlier Santhosh Kumar K
2026-05-27 17:55 ` [PATCH v3 07/13] spi: cadence-quadspi: add DQS support to read data capture Santhosh Kumar K
2026-05-27 18:17 ` sashiko-bot
2026-05-27 17:55 ` [PATCH v3 08/13] spi: cadence-quadspi: add PHY tuning support Santhosh Kumar K
2026-05-27 18:44 ` sashiko-bot [this message]
2026-05-28 8:54 ` Miquel Raynal
2026-05-27 17:55 ` [PATCH v3 09/13] spi: cadence-quadspi: reject 2-byte-address DDR ops on PHY-tunable hardware Santhosh Kumar K
2026-05-28 9:01 ` Miquel Raynal
2026-05-27 17:55 ` [PATCH v3 10/13] spi: cadence-quadspi: enable PHY for direct reads and indirect writes Santhosh Kumar K
2026-05-27 18:36 ` sashiko-bot
2026-05-28 9:09 ` Miquel Raynal
2026-05-27 17:55 ` [PATCH v3 11/13] mtd: spinand: run PHY tuning after init and update dirmap frequencies Santhosh Kumar K
2026-05-27 19:04 ` sashiko-bot
2026-05-28 9:27 ` Miquel Raynal
2026-05-27 17:55 ` [PATCH v3 12/13] mtd: spi-nor: extract read op template construction into helper Santhosh Kumar K
2026-05-27 17:55 ` [PATCH v3 13/13] mtd: spi-nor: run PHY tuning after init and update dirmap frequency Santhosh Kumar K
2026-05-27 18:59 ` sashiko-bot
2026-05-28 8:30 ` [PATCH v3 00/13] spi: cadence-quadspi: add PHY tuning support 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=20260527184405.3E9741F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=s-k6@ti.com \
--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