From b82b2dfc93d3c7729250e1107b7121775f5dfd40 Mon Sep 17 00:00:00 2001 From: Honghui Jiang Date: Fri, 14 Aug 2026 11:14:16 +0800 Subject: [PATCH] spi: Move __spi_unmap_msg() before __spi_map_msg() Move __spi_unmap_msg() above __spi_map_msg() so the mapping error path can call it without a forward declaration. This is a code-only relocation with no functional change. Suggested-by: Andy Shevchenko Signed-off-by: Honghui Jiang Reviewed-by: Andy Shevchenko Link: https://patch.msgid.link/20260814031419.43378-3-jiang_hh2019@163.com Signed-off-by: Mark Brown --- drivers/spi/spi.c | 48 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 0e86dc954713..bfb5ac93c8ee 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1418,7 +1418,29 @@ void spi_unmap_buf(struct spi_controller *ctlr, struct device *dev, spi_unmap_buf_attrs(ctlr, dev, sgt, dir, 0); } -static int __spi_unmap_msg(struct spi_controller *ctlr, struct spi_message *msg); +static int __spi_unmap_msg(struct spi_controller *ctlr, struct spi_message *msg) +{ + struct device *rx_dev = ctlr->cur_rx_dma_dev; + struct device *tx_dev = ctlr->cur_tx_dma_dev; + struct spi_transfer *xfer; + + list_for_each_entry(xfer, &msg->transfers, transfer_list) { + /* The sync has already been done after each transfer. */ + unsigned long attrs = DMA_ATTR_SKIP_CPU_SYNC; + + if (xfer->rx_sg_mapped) + spi_unmap_buf_attrs(ctlr, rx_dev, &xfer->rx_sg, + DMA_FROM_DEVICE, attrs); + xfer->rx_sg_mapped = false; + + if (xfer->tx_sg_mapped) + spi_unmap_buf_attrs(ctlr, tx_dev, &xfer->tx_sg, + DMA_TO_DEVICE, attrs); + xfer->tx_sg_mapped = false; + } + + return 0; +} static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg) { @@ -1487,30 +1509,6 @@ static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg) return ret; } -static int __spi_unmap_msg(struct spi_controller *ctlr, struct spi_message *msg) -{ - struct device *rx_dev = ctlr->cur_rx_dma_dev; - struct device *tx_dev = ctlr->cur_tx_dma_dev; - struct spi_transfer *xfer; - - list_for_each_entry(xfer, &msg->transfers, transfer_list) { - /* The sync has already been done after each transfer. */ - unsigned long attrs = DMA_ATTR_SKIP_CPU_SYNC; - - if (xfer->rx_sg_mapped) - spi_unmap_buf_attrs(ctlr, rx_dev, &xfer->rx_sg, - DMA_FROM_DEVICE, attrs); - xfer->rx_sg_mapped = false; - - if (xfer->tx_sg_mapped) - spi_unmap_buf_attrs(ctlr, tx_dev, &xfer->tx_sg, - DMA_TO_DEVICE, attrs); - xfer->tx_sg_mapped = false; - } - - return 0; -} - static void spi_dma_sync_for_device(struct spi_controller *ctlr, struct spi_transfer *xfer) {