spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption
Subsystems (2)
PATCH 1/1 spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruption
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.
--- drivers/spi/spi-rzv2h-rspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-rzv2h-rspi.c +2 -2
@@ -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,
Signature · 1 line
Felix Gu <[email protected]>
Quoted 7 lines · 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 <[email protected]>
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.
Quoted 9 lines
From: Wolfram Sang <[email protected]>
Sent: Friday, June 26, 2026 7:43 PMQuoted 5 lines · 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.
Quoted 8 lines
Quoted 2 lines
Fixes fa08b566860b ("spi: rzv2h-rspi: add support for DMA mode")Signed-off-by Felix Gu <[email protected]>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.
Fabrizio Castro
maintainerHi Cosmin,
Quoted 27 lines
From: Cosmin-Gabriel Tanislav <[email protected]>
Sent: 29 June 2026 11:22
To: wsa+renesas <[email protected]>; Felix Gu <[email protected]>
Cc: Fabrizio Castro <[email protected]>; Mark Brown <[email protected]>; linux- [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH] spi: rzv2h-rspi: Fix DMA transfer error handling for signal interruptionQuoted 9 lines
From: Wolfram Sang <[email protected]>
Sent: Friday, June 26, 2026 7:43 PMQuoted 5 lines · 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.Quoted 8 lines
Quoted 2 lines
Fixes fa08b566860b ("spi: rzv2h-rspi: add support for DMA mode")Signed-off-by Felix Gu <[email protected]>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.
Quoted 8 lines
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 /
-ERESTARTSYSpath 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
Quoted 2 lines
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.
Quoted 8 lines
From: wsa+renesas <[email protected]>
Sent: Monday, June 29, 2026 1:33 PMQuoted 1 line
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.
Quoted 3 lines
Reviewed-by Cosmin Tanislav <[email protected]>Tested-by Cosmin Tanislav <[email protected]>
Your explanations were very convincing, thank you for testing!
Quoted 7 lines · 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 <[email protected]>
Mark Brown
maintainerQuoted 1 line · Felix Gu
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