From 382ee011d5d9037dcbf5c90a207f80201f41dd2d Mon Sep 17 00:00:00 2001 From: Christoph Heller Date: Fri, 13 May 2022 19:01:05 +0200 Subject: [PATCH] drivers: flash: stm32h7x: Fix wrong flash write offset The flash_stm32_write_range() function of the STM32H7x flash driver partially uses a wrong flash program word size for certain SOC types when calculating the flash write offset. If the used SOC is not having a flash program word size of 256 bits / 32 bytes the written data might get corrupted, as the flash write offset value does not match the number of bytes that were actually written. Fixes #45568 Signed-off-by: Christoph Heller --- drivers/flash/flash_stm32h7x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/flash/flash_stm32h7x.c b/drivers/flash/flash_stm32h7x.c index c4ec73841ca..c8356460101 100644 --- a/drivers/flash/flash_stm32h7x.c +++ b/drivers/flash/flash_stm32h7x.c @@ -373,7 +373,7 @@ int flash_stm32_write_range(const struct device *dev, unsigned int offset, const uint8_t nbytes = FLASH_NB_32BITWORD_IN_FLASHWORD * 4; uint8_t unaligned_datas[nbytes]; - for (i = 0; i < len && i + 32 <= len; i += 32, offset += 32U) { + for (i = 0; i < len && i + nbytes <= len; i += nbytes, offset += nbytes) { rc = write_ndwords(dev, offset, (const uint64_t *) data + (i >> 3), ndwords);