diff mbox

[V2] spi: add missing cleanup in spi_map_msg on error

Message ID 1432548630-2202-1-git-send-email-kernel@martin.sperl.org (mailing list archive)
State New, archived
Headers show

Commit Message

Martin Sperl May 25, 2015, 10:10 a.m. UTC
From: Martin Sperl <kernel@martin.sperl.org>

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

Changelog:
[V1 -> V2]: for the cleanup to work propperly cur_msg_mapped needs to be
            set, as spi_unmap_msg checks for this condition and will not
            clean up otherwise (which happened in V1)

Comments

Mark Brown May 25, 2015, 1:05 p.m. UTC | #1
On Mon, May 25, 2015 at 10:10:29AM +0000, kernel@martin.sperl.org wrote:
> From: Martin Sperl <kernel@martin.sperl.org>

Please don't bury patches in reply to existing threads, and especially
don't send streams of multiple new patches in reply to each other at
once.  This makes it harder to spot new patches and confusing what's the
current code intended for review, you end up with a jumbled mess of
possibly related things some of which superceed each other.
diff mbox

Patch

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index d35c1a1..647a8bb 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -552,6 +552,7 @@  static int __spi_map_msg(struct spi_master *master, struct spi_message *msg)
 					  DMA_TO_DEVICE);
 			if (ret != 0)
 				return ret;
+			master->cur_msg_mapped = true;
 		}
 
 		if (xfer->rx_buf != NULL) {
@@ -563,11 +564,10 @@  static int __spi_map_msg(struct spi_master *master, struct spi_message *msg)
 					      DMA_TO_DEVICE);
 				return ret;
 			}
+			master->cur_msg_mapped = true;
 		}
 	}
 
-	master->cur_msg_mapped = true;
-
 	return 0;
 }
 
@@ -620,6 +620,7 @@  static int spi_map_msg(struct spi_master *master, struct spi_message *msg)
 	struct spi_transfer *xfer;
 	void *tmp;
 	unsigned int max_tx, max_rx;
+	int ret;
 
 	if (master->flags & (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX)) {
 		max_tx = 0;
@@ -662,7 +663,11 @@  static int spi_map_msg(struct spi_master *master, struct spi_message *msg)
 		}
 	}
 
-	return __spi_map_msg(master, msg);
+	ret = __spi_map_msg(master, msg);
+	if (ret)
+		spi_unmap_msg(master, msg);
+
+	return ret;
 }
 
 /*