summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2016-03-04 12:54:09 +0200
committerGerrit Code Review <gerrit@zephyrproject.org>2016-03-04 20:11:57 +0000
commit7c5563fd3ae1b859f1fa8c4f1079b6b53345612b (patch)
treef7d9296313398e47998b8f33108cf3f2e455fb39
parent62fc555c882b032dc5178ee5cb86c9979644a637 (diff)
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 <johan.hedberg@intel.com>
-rw-r--r--drivers/spi/spi_dw.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/spi/spi_dw.c b/drivers/spi/spi_dw.c
index 64a2ac10c..e0af9c130 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
}