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 <[email protected]>
Signed-off-by: Honghui Jiang <[email protected]>
---
 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 96f5058c7..e5b1531b9 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1373,6 +1373,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) {
                /*
@@ -1385,7 +1386,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)
-- 
2.43.0


Reply via email to