From af6aaacd42f74e2139391f9853d770d61ac430ce Mon Sep 17 00:00:00 2001 From: Honghui Jiang Date: Fri, 14 Aug 2026 11:14:17 +0800 Subject: [PATCH] spi: Clear current DMA devices when unmapping a message The current DMA device pointers remain set after a message has been unmapped. Existing users either check the corresponding mapped flag or access the pointers before finalizing the message, but retaining stale device pointers is fragile. Clear both pointers in spi_unmap_msg() after the internal unmap completes. Keep them intact in __spi_unmap_msg(), since that helper is also used during partial-map unwind and the in-message DMA-to-PIO fallback, before processing of the current message is complete. Suggested-by: Andy Shevchenko Signed-off-by: Honghui Jiang Reviewed-by: Andy Shevchenko Link: https://patch.msgid.link/20260814031419.43378-4-jiang_hh2019@163.com Signed-off-by: Mark Brown --- drivers/spi/spi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index bfb5ac93c8ee..ebda5855bba4 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1560,6 +1560,7 @@ static inline int spi_unmap_msg(struct spi_controller *ctlr, struct spi_message *msg) { struct spi_transfer *xfer; + int ret; list_for_each_entry(xfer, &msg->transfers, transfer_list) { /* @@ -1572,7 +1573,12 @@ static inline int spi_unmap_msg(struct spi_controller *ctlr, xfer->rx_buf = NULL; } - return __spi_unmap_msg(ctlr, msg); + ret = __spi_unmap_msg(ctlr, msg); + + ctlr->cur_rx_dma_dev = NULL; + ctlr->cur_tx_dma_dev = NULL; + + return ret; } static int spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)