util/nvmutil: safer calculated_checksum

we rely on uint16_t wrapping, but some platforms may
behave weirdly.

cast as uint32_t and then cast back, on return, with
an explicit mask beforehand.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-09 17:07:53 +00:00
parent 61015dbc6c
commit 8f719f80b8
+3 -3
View File
@@ -1132,12 +1132,12 @@ static uint16_t
calculated_checksum(size_t p) calculated_checksum(size_t p)
{ {
size_t c; size_t c;
uint16_t val16 = 0; uint32_t val16 = 0;
for (c = 0; c < NVM_CHECKSUM_WORD; c++) for (c = 0; c < NVM_CHECKSUM_WORD; c++)
val16 += nvm_word(c, p); val16 += (uint32_t)nvm_word(c, p);
return NVM_CHECKSUM - val16; return (uint16_t)((NVM_CHECKSUM - val16) & 0xffff);
} }
/* /*