summaryrefslogtreecommitdiff
path: root/util/nvmutil
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-09-19 16:05:34 +0100
committerLeah Rowe <leah@libreboot.org>2023-09-19 16:05:34 +0100
commitd9bed115018bae46ca6b20a9f8f55ee434dd8cfa (patch)
tree15764c5ec6f64017d00b44909c91f2e74b78ebad /util/nvmutil
parent5e8013601a7592721a908252625eb785ae9f7a8b (diff)
util/nvmutil: further optimise swap command
don't swap pointers at all. handle it in the for loop. 258 sloccount now, versus 261. Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil')
-rw-r--r--util/nvmutil/nvmutil.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 79b0ceeb..36ef6b01 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -279,15 +279,12 @@ void
writeGbeFile(void)
{
errno = 0;
- if (cmd == writeGbeFile) {
- err_if(!(validChecksum(0) || validChecksum(1)));
- xorswap(gbe[0], gbe[1]);
- }
- for (int p = 0; p < 2; p++) {
- if ((!nvmPartModified[p]) && (gbe[0] <= gbe[1]))
+ err_if((cmd == writeGbeFile) && !(validChecksum(0) || validChecksum(1)));
+ for (int p = 0, x = (cmd == writeGbeFile) ? 1 : 0; p < 2; p++) {
+ if ((!nvmPartModified[p]) && (cmd != writeGbeFile))
continue;
- handle_endianness(p);
- err_if(pwrite(fd, (uint8_t *) gbe[p], nf, p << 12) == -1);
+ handle_endianness(p^x);
+ err_if(pwrite(fd, (uint8_t *) gbe[p^x], nf, p << 12) == -1);
}
err_if(close(fd) == -1);
}