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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Martin Sperl <kernel@xxxxxxxxxxxxxxxx>

Signed-off-by: Martin Sperl <kernel@xxxxxxxxxxxxxxxx>
---
 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)

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;
 }
 
 /*
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux