[V1,2/3] spi: core: add a warning when prepare_message uses spi_res and unprepare_message
diff mbox series

Message ID 20190509105533.24275-3-kernel@martin.sperl.org
State New, archived
Headers show
Series
  • spi: core: correct ordering of unprepare and resources
Related show

Commit Message

Martin Sperl May 9, 2019, 10:55 a.m. UTC
From: Martin Sperl <kernel@martin.sperl.org>

Add a warning about a potential cleanup inconsistency when both
prepare_message and unprepare_message are defined by the bus driver
and prepare_message is using spi_res_add.

Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
---
 drivers/spi/spi.c | 6 ++++++
 1 file changed, 6 insertions(+)

--
2.11.0

Patch
diff mbox series

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 1dfb19140bbe..78fe46bf6f41 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1317,6 +1317,7 @@  static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread)
 	trace_spi_message_start(ctlr->cur_msg);

 	if (ctlr->prepare_message) {
+		struct list_head *tail = ctlr->cur_msg->resources.prev;
 		ret = ctlr->prepare_message(ctlr, ctlr->cur_msg);
 		if (ret) {
 			dev_err(&ctlr->dev, "failed to prepare message: %d\n",
@@ -1325,6 +1326,11 @@  static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread)
 			spi_finalize_current_message(ctlr);
 			goto out;
 		}
+		/* warn about possible issues on finalize */
+		if (ctlr->unprepare_message &&
+		    tail != ctlr->cur_msg->resources.prev)
+			dev_warn_once(&ctlr->dev,
+				      "spi_message.resource is modified and unprepare_message is defined - this can give unexpected results during finalize\n");
 		ctlr->cur_msg_prepared = true;
 	}