Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xianwei Zhao" <xianwei.zhao@amlogic.com>
Cc: neil.armstrong@linaro.org, devicetree@vger.kernel.org,
	linux-amlogic@lists.infradead.org, robh@kernel.org,
	conor+dt@kernel.org
Subject: Re: [PATCH v3 2/4] spi: amlogic: spisg: Fix transfer size limit and timeout handling
Date: Fri, 31 Jul 2026 09:22:13 +0000	[thread overview]
Message-ID: <20260731092213.9D5E71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260731-a9-spisg-v3-2-a15da3f70029@amlogic.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] The newly added timeout abort path stops the controller but fails to synchronize or disable pending interrupts, causing a race condition where a late interrupt can falsely complete a subsequent transfer.

Pre-existing issues:
- [High] Transfers exceeding SPISG_BLOCK_MAX blocks are silently truncated by the driver because it caps the block count but fails to implement the max_transfer_size controller callback.
- [High] The driver incorrectly mixes `devm_clk_get_enabled()` with manual `clk_disable_unprepare()` calls, leading to unbalanced clock reference counting.
--

--- Patch [2]: [PATCH v3 2/4] spi: amlogic: spisg: Fix transfer size limit and timeout handling ---
commit f3597777f9b3ab326fe08698fcd9389c455e53d4
Author: Xianwei Zhao <xianwei.zhao@amlogic.com>

spi: amlogic: spisg: Fix transfer size limit and timeout handling

The commit reduces SPISG_BLOCK_MAX to avoid zero-length transfers and fixes
a 64-bit delay calculation. It also clears the descriptor list register on a
transfer timeout to stop the controller.

> diff --git a/drivers/spi/spi-amlogic-spisg.c b/drivers/spi/spi-amlogic-spisg.c
> --- a/drivers/spi/spi-amlogic-spisg.c
> +++ b/drivers/spi/spi-amlogic-spisg.c
> @@ -95,7 +95,7 @@
>  
>  #define SPISG_MAX_REG			0x40
>  
> -#define SPISG_BLOCK_MAX			0x100000
> +#define SPISG_BLOCK_MAX			0xFFFFF

[Severity: High]
This isn't a bug introduced by this patch, but does the driver silently
truncate large transfers?

In aml_spisg_probe(), the driver sets ctlr->max_dma_len = SPISG_BLOCK_MAX,
but it does not implement the max_transfer_size controller callback.

When a transfer is larger than SPISG_BLOCK_MAX, aml_spisg_setup_transfer()
silently caps it:

	blocks = min_t(int, blocks, SPISG_BLOCK_MAX);

Since the SPI core isn't aware of the maximum transfer size limit, it could
submit oversized transfers that get silently truncated. This could leave DMA
buffers partially uninitialized on RX. Should we implement the
ctlr->max_transfer_size callback to prevent this?

[ ... ]

> @@ -565,10 +565,13 @@ static int aml_spisg_transfer_one_message(struct spi_controller *ctlr,
>  	aml_spisg_pending(spisg, descs_paddr, false, true);
>  	if (wait_for_completion_timeout(&spisg->completion,
>  					spi_controller_is_target(spisg->controller) ?
> -					MAX_SCHEDULE_TIMEOUT : msecs_to_jiffies(ms)))
> +					MAX_SCHEDULE_TIMEOUT : msecs_to_jiffies(ms))) {
>  		ret = spisg->status ? -EIO : 0;
> -	else
> +	} else {
> +		/* stop transfer */
> +		regmap_write(spisg->map, SPISG_REG_DESC_LIST_H, 0);
>  		ret = -ETIMEDOUT;
> +	}

[Severity: High]
Could this timeout path race with a late interrupt?

By stopping the controller without synchronizing or masking the IRQ, a
delayed interrupt might still arrive. If it does, aml_spisg_irq()
unconditionally completes it:

	complete(&spisg->completion);

If the SPI core immediately enqueues the next message, could this late
interrupt prematurely complete the new transfer and prematurely unmap its
active DMA buffers?

[Severity: High]
This is a pre-existing issue, but does the driver have an unbalanced clock
reference count issue?

The driver acquires clocks using devm_clk_get_enabled(), but manually
disables them during error handling and removal. For example, in the error
path of aml_spisg_probe():

out_clk:
	if (spisg->core)
		clk_disable_unprepare(spisg->core);
	clk_disable_unprepare(spisg->pclk);

Since these are devm-managed clocks, the cleanup framework will also
disable them, which results in a double-disable. Should these manual
clk_disable_unprepare() calls be removed, or should the driver use the
non-devm clock getters?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260731-a9-spisg-v3-0-a15da3f70029@amlogic.com?part=2

  reply	other threads:[~2026-07-31  9:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-31  9:08 [PATCH v3 0/4] spi: add support for Amlogic A9 Xianwei Zhao via B4 Relay
2026-07-31  9:08 ` [PATCH v3 1/4] spi: dt-bindings: amlogic: spisg: Document A9-specific properties Xianwei Zhao via B4 Relay
2026-07-31  9:08 ` [PATCH v3 2/4] spi: amlogic: spisg: Fix transfer size limit and timeout handling Xianwei Zhao via B4 Relay
2026-07-31  9:22   ` sashiko-bot [this message]
2026-07-31  9:08 ` [PATCH v3 3/4] spi: amlogic: spisg: Fix the incorrect keep_ss of the last descriptor Xianwei Zhao via B4 Relay
2026-07-31  9:20   ` sashiko-bot
2026-07-31  9:08 ` [PATCH v3 4/4] spi: amlogic: spisg: Add support for A9 controller features Xianwei Zhao via B4 Relay
2026-07-31  9:19   ` 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=20260731092213.9D5E71F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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