summaryrefslogtreecommitdiff
path: root/drivers/bootcount
diff options
context:
space:
mode:
authorNiko Mauno <[email protected]>2026-02-04 15:17:36 +0200
committerTom Rini <[email protected]>2026-02-18 16:35:07 -0600
commit05b56599b5b13a504d8ed66db27a4446f8b9acc5 (patch)
tree7783f3ef33f7d17a56aab14d9aab2b86a8889eb4 /drivers/bootcount
parent27e1924ffaa9361542d4cf75a9b73613fa45d007 (diff)
bootcount: Fix potential clobbering issue
When storing the single word bootcount value, apply the bootcount count mask to prevent clobbering the magic half of the value. Signed-off-by: Niko Mauno <[email protected]>
Diffstat (limited to 'drivers/bootcount')
-rw-r--r--drivers/bootcount/bootcount.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/bootcount/bootcount.c b/drivers/bootcount/bootcount.c
index 454e50591df..2c0114d9705 100644
--- a/drivers/bootcount/bootcount.c
+++ b/drivers/bootcount/bootcount.c
@@ -19,7 +19,8 @@ __weak void bootcount_store(ulong a)
uintptr_t flush_end;
#if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
- raw_bootcount_store(reg, (CONFIG_SYS_BOOTCOUNT_MAGIC & BOOTCOUNT_MAGIC_MASK) | a);
+ raw_bootcount_store(reg, (CONFIG_SYS_BOOTCOUNT_MAGIC & BOOTCOUNT_MAGIC_MASK)
+ | (a & BOOTCOUNT_COUNT_MASK));
flush_end = roundup(CONFIG_SYS_BOOTCOUNT_ADDR + 4,
CONFIG_SYS_CACHELINE_SIZE);
@@ -98,7 +99,8 @@ static int bootcount_mem_set(struct udevice *dev, const u32 a)
uintptr_t flush_end;
if (priv->singleword) {
- raw_bootcount_store(reg, (magic & BOOTCOUNT_MAGIC_MASK) | a);
+ raw_bootcount_store(reg, (magic & BOOTCOUNT_MAGIC_MASK)
+ | (a & BOOTCOUNT_COUNT_MASK));
flush_end = roundup(priv->base + 4,
CONFIG_SYS_CACHELINE_SIZE);
} else {