Linux SPI subsystem development
 help / color / mirror / Atom feed
* [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption
@ 2026-06-26 16:02 Felix Gu
  2026-06-26 16:42 ` Wolfram Sang
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Felix Gu @ 2026-06-26 16:02 UTC (permalink / raw)
  To: Fabrizio Castro, Mark Brown, Cosmin Tanislav
  Cc: linux-spi, linux-renesas-soc, linux-kernel, Felix Gu

wait_event_interruptible_timeout() can return a negative error code when
interrupted by a signal. The original code treated all non-zero return
values as success, which would incorrectly synchronize DMA channels and
return 0 instead of propagating the interruption error.

Fixes: fa08b566860b ("spi: rzv2h-rspi: add support for DMA mode")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/spi/spi-rzv2h-rspi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-rzv2h-rspi.c b/drivers/spi/spi-rzv2h-rspi.c
index 0738d448160d..daa4239b0fe0 100644
--- a/drivers/spi/spi-rzv2h-rspi.c
+++ b/drivers/spi/spi-rzv2h-rspi.c
@@ -366,14 +366,14 @@ static int rzv2h_rspi_transfer_dma(struct rzv2h_rspi_priv *rspi,
 	rzv2h_rspi_clear_all_irqs(rspi);
 
 	ret = wait_event_interruptible_timeout(rspi->wait, rspi->dma_callbacked, HZ);
-	if (ret) {
+	if (ret > 0) {
 		dmaengine_synchronize(rspi->controller->dma_tx);
 		dmaengine_synchronize(rspi->controller->dma_rx);
 		ret = 0;
 	} else {
 		dmaengine_terminate_sync(rspi->controller->dma_tx);
 		dmaengine_terminate_sync(rspi->controller->dma_rx);
-		ret = -ETIMEDOUT;
+		ret = ret ?: -ETIMEDOUT;
 	}
 
 	enable_irq(rspi->irq_rx);

---
base-commit: 30ffa8de54e5cc80d93fd211ca134d1764a7011f
change-id: 20260626-rspi-f0a56c6e5eca

Best regards,
--  
Felix Gu <ustc.gu@gmail.com>


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption
  2026-06-26 16:02 [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption Felix Gu
@ 2026-06-26 16:42 ` Wolfram Sang
  2026-06-29 10:22   ` Cosmin-Gabriel Tanislav
  2026-06-29 16:33 ` Wolfram Sang
  2026-06-30 18:58 ` Mark Brown
  2 siblings, 1 reply; 9+ messages in thread
From: Wolfram Sang @ 2026-06-26 16:42 UTC (permalink / raw)
  To: Felix Gu
  Cc: Fabrizio Castro, Mark Brown, Cosmin Tanislav, linux-spi,
	linux-renesas-soc, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 808 bytes --]

On Sat, Jun 27, 2026 at 12:02:29AM +0800, Felix Gu wrote:
> wait_event_interruptible_timeout() can return a negative error code when
> interrupted by a signal. The original code treated all non-zero return
> values as success, which would incorrectly synchronize DMA channels and
> return 0 instead of propagating the interruption error.
> 
> Fixes: fa08b566860b ("spi: rzv2h-rspi: add support for DMA mode")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>

Patch looks correct. But it makes me wonder if interrupting the transfer
has actually been tested? Cosmin, can you recall such tests? From my I2C
experience, I know it can be hard to get the state maching back to a
consistent state. Sometimes, it was preferred to simply use
wait_event_timeout() instead and drop interruptible support.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption
  2026-06-26 16:42 ` Wolfram Sang
@ 2026-06-29 10:22   ` Cosmin-Gabriel Tanislav
  2026-06-29 10:29     ` Fabrizio Castro
  2026-06-29 10:32     ` wsa+renesas
  0 siblings, 2 replies; 9+ messages in thread
From: Cosmin-Gabriel Tanislav @ 2026-06-29 10:22 UTC (permalink / raw)
  To: wsa+renesas, Felix Gu
  Cc: Fabrizio Castro, Mark Brown, linux-spi@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org

> From: Wolfram Sang <wsa+renesas@sang-engineering.com>
> Sent: Friday, June 26, 2026 7:43 PM
> 
> On Sat, Jun 27, 2026 at 12:02:29AM +0800, Felix Gu wrote:
> > wait_event_interruptible_timeout() can return a negative error code when
> > interrupted by a signal. The original code treated all non-zero return
> > values as success, which would incorrectly synchronize DMA channels and
> > return 0 instead of propagating the interruption error.
> >
> > Fixes: fa08b566860b ("spi: rzv2h-rspi: add support for DMA mode")
> > Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> 
> Patch looks correct. But it makes me wonder if interrupting the transfer
> has actually been tested? Cosmin, can you recall such tests? From my I2C
> experience, I know it can be hard to get the state maching back to a
> consistent state. Sometimes, it was preferred to simply use
> wait_event_timeout() instead and drop interruptible support.

Hi Wolfram, Felix.

I don't think we tested interrupting the transfer.

I can run some tests locally this week and see how it behaves.

Looking at it now, the timeout / -ERESTARTSYS path might need some
extra logic to put the controller in a good state.

I also think the patch is correct and should be accepted for now.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption
  2026-06-29 10:22   ` Cosmin-Gabriel Tanislav
@ 2026-06-29 10:29     ` Fabrizio Castro
  2026-06-29 10:32     ` wsa+renesas
  1 sibling, 0 replies; 9+ messages in thread
From: Fabrizio Castro @ 2026-06-29 10:29 UTC (permalink / raw)
  To: Cosmin-Gabriel Tanislav, wsa+renesas, Felix Gu
  Cc: Mark Brown, linux-spi@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org

Hi Cosmin,

> From: Cosmin-Gabriel Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
> Sent: 29 June 2026 11:22
> To: wsa+renesas <wsa+renesas@sang-engineering.com>; Felix Gu <ustc.gu@gmail.com>
> Cc: Fabrizio Castro <fabrizio.castro.jz@renesas.com>; Mark Brown <broonie@kernel.org>; linux-
> spi@vger.kernel.org; linux-renesas-soc@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: RE: [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption
> 
> > From: Wolfram Sang <wsa+renesas@sang-engineering.com>
> > Sent: Friday, June 26, 2026 7:43 PM
> >
> > On Sat, Jun 27, 2026 at 12:02:29AM +0800, Felix Gu wrote:
> > > wait_event_interruptible_timeout() can return a negative error code when
> > > interrupted by a signal. The original code treated all non-zero return
> > > values as success, which would incorrectly synchronize DMA channels and
> > > return 0 instead of propagating the interruption error.
> > >
> > > Fixes: fa08b566860b ("spi: rzv2h-rspi: add support for DMA mode")
> > > Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> >
> > Patch looks correct. But it makes me wonder if interrupting the transfer
> > has actually been tested? Cosmin, can you recall such tests? From my I2C
> > experience, I know it can be hard to get the state maching back to a
> > consistent state. Sometimes, it was preferred to simply use
> > wait_event_timeout() instead and drop interruptible support.
> 
> Hi Wolfram, Felix.
> 
> I don't think we tested interrupting the transfer.
> 
> I can run some tests locally this week and see how it behaves.
> 
> Looking at it now, the timeout / -ERESTARTSYS path might need some
> extra logic to put the controller in a good state.
> 
> I also think the patch is correct and should be accepted for now.


I think perhaps let's test it before accepting the patch.

Cheers,
Fab


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption
  2026-06-29 10:22   ` Cosmin-Gabriel Tanislav
  2026-06-29 10:29     ` Fabrizio Castro
@ 2026-06-29 10:32     ` wsa+renesas
  2026-06-29 14:33       ` Cosmin-Gabriel Tanislav
  1 sibling, 1 reply; 9+ messages in thread
From: wsa+renesas @ 2026-06-29 10:32 UTC (permalink / raw)
  To: Cosmin-Gabriel Tanislav
  Cc: Felix Gu, Fabrizio Castro, Mark Brown, linux-spi@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org


> I also think the patch is correct and should be accepted for now.

To bring a broken state into a less but still broken state? I don't
agree.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption
  2026-06-29 10:32     ` wsa+renesas
@ 2026-06-29 14:33       ` Cosmin-Gabriel Tanislav
  2026-06-29 16:32         ` wsa+renesas
  0 siblings, 1 reply; 9+ messages in thread
From: Cosmin-Gabriel Tanislav @ 2026-06-29 14:33 UTC (permalink / raw)
  To: wsa+renesas
  Cc: Felix Gu, Fabrizio Castro, Mark Brown, linux-spi@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org

> From: wsa+renesas <wsa+renesas@sang-engineering.com>
> Sent: Monday, June 29, 2026 1:33 PM
> 
> 
> > I also think the patch is correct and should be accepted for now.
> 
> To bring a broken state into a less but still broken state? I don't
> agree.

I tested what happens both in the timeout case and in the interrupt
case:

In the timeout case, the SPI controller and the DMA controller recover
fine.

In the interrupt case, the SPI controller recovers fine but the DMA
controller does not, because dmaengine_terminate_sync() is not called
and a large DMA transfer does not complete within the 100ms timeout
found inside rz_dmac_device_synchronize().

With this patch applied, interrupt case ends up in the same branch
as the timeout case, which correctly aborts the transfer.

By the way, the mechanism for recovering the SPI controller is handled
by the SPI core, as it calls the .unprepare_message() callback even in
the error case, and the next message re-setups everything correctly.

Please let me know if you still have doubts or if I should go more
in-depth with the explanations.

Reviewed-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
Tested-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption
  2026-06-29 14:33       ` Cosmin-Gabriel Tanislav
@ 2026-06-29 16:32         ` wsa+renesas
  0 siblings, 0 replies; 9+ messages in thread
From: wsa+renesas @ 2026-06-29 16:32 UTC (permalink / raw)
  To: Cosmin-Gabriel Tanislav
  Cc: Felix Gu, Fabrizio Castro, Mark Brown, linux-spi@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 208 bytes --]


> Reviewed-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
> Tested-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>

Your explanations were very convincing, thank you for testing!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption
  2026-06-26 16:02 [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption Felix Gu
  2026-06-26 16:42 ` Wolfram Sang
@ 2026-06-29 16:33 ` Wolfram Sang
  2026-06-30 18:58 ` Mark Brown
  2 siblings, 0 replies; 9+ messages in thread
From: Wolfram Sang @ 2026-06-29 16:33 UTC (permalink / raw)
  To: Felix Gu
  Cc: Fabrizio Castro, Mark Brown, Cosmin Tanislav, linux-spi,
	linux-renesas-soc, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 529 bytes --]

On Sat, Jun 27, 2026 at 12:02:29AM +0800, Felix Gu wrote:
> wait_event_interruptible_timeout() can return a negative error code when
> interrupted by a signal. The original code treated all non-zero return
> values as success, which would incorrectly synchronize DMA channels and
> return 0 instead of propagating the interruption error.
> 
> Fixes: fa08b566860b ("spi: rzv2h-rspi: add support for DMA mode")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>

Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption
  2026-06-26 16:02 [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption Felix Gu
  2026-06-26 16:42 ` Wolfram Sang
  2026-06-29 16:33 ` Wolfram Sang
@ 2026-06-30 18:58 ` Mark Brown
  2 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2026-06-30 18:58 UTC (permalink / raw)
  To: Fabrizio Castro, Cosmin Tanislav, Felix Gu
  Cc: linux-spi, linux-renesas-soc, linux-kernel

On Sat, 27 Jun 2026 00:02:29 +0800, Felix Gu wrote:
> spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.2

Thanks!

[1/1] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption
      https://git.kernel.org/broonie/spi/c/7fc2c3dcae28

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-07-01 11:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-26 16:02 [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption Felix Gu
2026-06-26 16:42 ` Wolfram Sang
2026-06-29 10:22   ` Cosmin-Gabriel Tanislav
2026-06-29 10:29     ` Fabrizio Castro
2026-06-29 10:32     ` wsa+renesas
2026-06-29 14:33       ` Cosmin-Gabriel Tanislav
2026-06-29 16:32         ` wsa+renesas
2026-06-29 16:33 ` Wolfram Sang
2026-06-30 18:58 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox