From 0b79ae3524c1fc3dd19ec821abe00bbb9fc6429c Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 22 Feb 2021 10:24:39 +0100 Subject: [PATCH] drivers/mtd_flashpage: require the write source buffer to be aligned --- drivers/mtd_flashpage/mtd_flashpage.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/mtd_flashpage/mtd_flashpage.c b/drivers/mtd_flashpage/mtd_flashpage.c index 3229476ab9..bf5f58997b 100644 --- a/drivers/mtd_flashpage/mtd_flashpage.c +++ b/drivers/mtd_flashpage/mtd_flashpage.c @@ -24,6 +24,7 @@ #include #include "architecture.h" +#include "cpu.h" #include "cpu_conf.h" #include "mtd_flashpage.h" #include "periph/flashpage.h" @@ -53,6 +54,11 @@ static int _write(mtd_dev_t *dev, const void *buf, uint32_t addr, uint32_t size) { (void)dev; +#ifndef CPU_HAS_UNALIGNED_ACCESS + if ((uintptr_t)buf % sizeof(uword_t)) { + return -EINVAL; + } +#endif if (addr % FLASHPAGE_WRITE_BLOCK_ALIGNMENT) { return -EINVAL; }