From 9fbb81e8a44bf9d249e6dbfed175c5a546eeb62c Mon Sep 17 00:00:00 2001 From: Michal Lenc Date: Mon, 2 Dec 2024 10:52:29 +0100 Subject: [PATCH] samv7: fix bytes to words calculation in user signature read EEFC read sequence requires read length in words instead of bytes, therefore bytes given by the user has to be recalculated to words. The calculation however had a mistake in brackets and was just adding 1 to buflen instead of recalculating it to 4 byte words. This caused global array g_page_buffer to overflow for some reads. This fixes the calculation. Signed-off-by: Michal Lenc --- arch/arm/src/samv7/sam_us.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/src/samv7/sam_us.c b/arch/arm/src/samv7/sam_us.c index aca0376617..a04c42cade 100644 --- a/arch/arm/src/samv7/sam_us.c +++ b/arch/arm/src/samv7/sam_us.c @@ -177,7 +177,7 @@ int sam_read_user_signature(void *buffer, size_t buflen) /* sam_eefc_readsequence requires read length in bit words. */ - nwords = (buflen + sizeof(uint32_t) / sizeof(uint32_t)); + nwords = (buflen + sizeof(uint32_t)) / sizeof(uint32_t); sam_eefc_readsequence(FCMD_STUS, FCMD_SPUS, g_page_buffer, nwords); /* Copy local buffer to void *buffer provided by the user. */