summaryrefslogtreecommitdiff
path: root/util/nvmutil
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-06-01 12:21:55 +0100
committerLeah Rowe <leah@libreboot.org>2023-06-01 12:21:55 +0100
commitb49da12dad4916a5678e35b1909bdc529a6d8474 (patch)
tree7c356fb265fa2b8ab81ec6dfd5dd4d0b578041dc /util/nvmutil
parent9aa34f1e20263c8b25d4865f3b68db2e985ce5d8 (diff)
util/nvmutil: only swap/copy if checksum is valid
in practise, the file was never written unless the checksum was valid, but in the same of sloccount reduction i made it do the swap/copy before checking. while functionally ok, it never sat right with me. this is one example of where sloc count doesn't mean everything. code correctness is critical Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil')
-rw-r--r--util/nvmutil/nvmutil.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 3a050644..77b33aa2 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -205,16 +205,18 @@ cmd_brick(void)
void
cmd_swap(void)
{
- xorswap(gbe[0], gbe[1]); /* speedhack: swap ptr, not words */
gbeFileModified = nvmPartModified[0] = nvmPartModified[1]
= validChecksum(1) | validChecksum(0);
+ if (gbeFileModified)
+ xorswap(gbe[0], gbe[1]); /* speedhack: swap ptr, not words */
}
void
cmd_copy(void)
{
- gbe[part ^ 1] = gbe[part]; /* speedhack: copy ptr, not words */
gbeFileModified = nvmPartModified[part ^ 1] = validChecksum(part);
+ if (gbeFileModified)
+ gbe[part ^ 1] = gbe[part]; /* speedhack: copy ptr, not words */
}
int