From 7c5563fd3ae1b859f1fa8c4f1079b6b53345612b Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 4 Mar 2016 12:54:09 +0200 Subject: [PATCH] drivers/spi: dw: Fix unaligned access The buffers aren't guaranteed to be aligned so that they're always aligned for uint16_t or uint32_t data. Use the available unaligned access macros to read/write the data. Change-Id: Ie87c108aa370af196b9c759b59ed7fb9d1ed6183 Signed-off-by: Johan Hedberg --- drivers/spi/spi_dw.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi_dw.c b/drivers/spi/spi_dw.c index 64a2ac10c1d..e0af9c130cf 100644 --- a/drivers/spi/spi_dw.c +++ b/drivers/spi/spi_dw.c @@ -103,14 +103,14 @@ static void push_data(struct device *dev) if (spi->tx_buf && spi->tx_buf_len > 0) { switch (spi->dfs) { case 1: - data = *(uint8_t *)(spi->tx_buf); + data = UNALIGNED_GET((uint8_t *)(spi->tx_buf)); break; case 2: - data = *(uint16_t *)(spi->tx_buf); + data = UNALIGNED_GET((uint16_t *)(spi->tx_buf)); break; #ifndef CONFIG_ARC case 4: - data = *(uint32_t *)(spi->tx_buf); + data = UNALIGNED_GET((uint32_t *)(spi->tx_buf)); break; #endif } @@ -156,14 +156,14 @@ static void pull_data(struct device *dev) if (spi->rx_buf && spi->rx_buf_len > 0) { switch (spi->dfs) { case 1: - *(uint8_t *)(spi->rx_buf) = (uint8_t)data; + UNALIGNED_PUT(data, (uint8_t *)spi->rx_buf); break; case 2: - *(uint16_t *)(spi->rx_buf) = (uint16_t)data; + UNALIGNED_PUT(data, (uint16_t *)spi->rx_buf); break; #ifndef CONFIG_ARC case 4: - *(uint32_t *)(spi->rx_buf) = (uint32_t)data; + UNALIGNED_PUT(data, (uint32_t *)spi->rx_buf); break; #endif }