util/nvmutil: tidy up write_gbe

by handling close() in main, we can reduce the
indendation in write_gbe and generally make it
much easier to read.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-03 17:09:33 +00:00
parent 86665c9d22
commit 8faa36eb64
+13 -7
View File
@@ -122,6 +122,8 @@ main(int argc, char *argv[])
(*cmd)(); (*cmd)();
write_gbe(); write_gbe();
err_if(close(fd) == -1);
err_if((errno != 0) && (cmd != cmd_dump)); err_if((errno != 0) && (cmd != cmd_dump));
return errno ? EXIT_FAILURE : EXIT_SUCCESS; return errno ? EXIT_FAILURE : EXIT_SUCCESS;
} }
@@ -520,21 +522,25 @@ write_gbe(void)
{ {
int p; int p;
if (flags != O_RDONLY) if (flags == O_RDONLY)
for (p = 0; p < 2; p++) return;
if (part_modified[p])
write_gbe_part(p); for (p = 0; p < 2; p++) {
err_if(close(fd) == -1); if (part_modified[p])
write_gbe_part(p);
}
} }
static void static void
write_gbe_part(int p) write_gbe_part(int p)
{ {
swap(p); /* swap bytes on big-endian host CPUs */ swap(p); /* swap bytes on big-endian host CPUs */
if(pwrite(fd, buf + (SIZE_4KB * p), SIZE_4KB, p * partsize)
!= SIZE_4KB) if (pwrite(fd, buf + (SIZE_4KB * p),
SIZE_4KB, p * partsize) != SIZE_4KB) {
err(set_err(ECANCELED), err(set_err(ECANCELED),
"Can't write %d b to '%s' p%d", SIZE_4KB, fname, p); "Can't write %d b to '%s' p%d", SIZE_4KB, fname, p);
}
} }
static void static void