From 96869ff3ff63b66e454f8f56c5f3a3ec0b801d21 Mon Sep 17 00:00:00 2001 From: Tomislav Milkovic Date: Thu, 15 Jun 2023 10:57:04 +0200 Subject: [PATCH] drivers: flash: flash_stm32h7x: Fix STM32H7 unaligned read access Due to source data pointer having no alignment constraint, extra care needs to be taken when reading source data as dword Signed-off-by: Tomislav Milkovic --- drivers/flash/flash_stm32h7x.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/flash/flash_stm32h7x.c b/drivers/flash/flash_stm32h7x.c index a386df730fb..61394164c1b 100644 --- a/drivers/flash/flash_stm32h7x.c +++ b/drivers/flash/flash_stm32h7x.c @@ -343,7 +343,8 @@ static int write_ndwords(const struct device *dev, /* Perform the data write operation at the desired memory address */ for (i = 0; i < n; ++i) { - flash[i] = data[i]; + /* Source dword may be unaligned, so take extra care when dereferencing it */ + flash[i] = UNALIGNED_GET(data + i); /* Flush the data write */ barrier_dsync_fence_full();