From b49da12dad4916a5678e35b1909bdc529a6d8474 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Thu, 1 Jun 2023 12:21:55 +0100 Subject: 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 --- util/nvmutil/nvmutil.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'util/nvmutil') 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 -- cgit v1.2.1