mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Honghui Jiang <jiang_hh2019@163.com>
To: Mark Brown <broonie@kernel.org>
Cc: Andy Shevchenko <andy@kernel.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Serge Semin <fancer.lancer@gmail.com>,
	Brendan Higgins <brendan.higgins@linux.dev>,
	David Gow <david@davidgow.net>, Rae Moar <raemoar63@gmail.com>,
	linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
	Honghui Jiang <jiang_hh2019@163.com>
Subject: [PATCH v2 3/4] spi: Clear current DMA devices when unmapping a message
Date: Fri, 14 Aug 2026 11:14:17 +0800	[thread overview]
Message-ID: <20260814031419.43378-4-jiang_hh2019@163.com> (raw)
In-Reply-To: <20260814031419.43378-1-jiang_hh2019@163.com>

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 <andy@kernel.org>
Signed-off-by: Honghui Jiang <jiang_hh2019@163.com>
---
 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


  parent reply	other threads:[~2026-08-14  3:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14  3:14 [PATCH v2 0/4] spi: Fix DMA mapping ownership on partial map failure Honghui Jiang
2026-08-14  3:14 ` [PATCH v2 1/4] " Honghui Jiang
2026-08-14  3:14 ` [PATCH v2 2/4] spi: Move __spi_unmap_msg() before __spi_map_msg() Honghui Jiang
2026-08-14  3:14 ` Honghui Jiang [this message]
2026-08-14  3:14 ` [PATCH v2 4/4] spi: Add KUnit coverage for DMA mapping error paths Honghui Jiang
2026-08-14 12:27   ` Andy Shevchenko
2026-08-14 12:49     ` Mark Brown
2026-08-14 17:38       ` Honghui  Jiang
2026-08-14 17:41         ` Mark Brown
2026-08-15  2:32         ` David Gow
2026-08-14 12:28 ` [PATCH v2 0/4] spi: Fix DMA mapping ownership on partial map failure Andy Shevchenko
2026-08-14 15:49 ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260814031419.43378-4-jiang_hh2019@163.com \
    --to=jiang_hh2019@163.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy@kernel.org \
    --cc=brendan.higgins@linux.dev \
    --cc=broonie@kernel.org \
    --cc=david@davidgow.net \
    --cc=fancer.lancer@gmail.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=raemoar63@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®