summaryrefslogtreecommitdiff
path: root/util/nvmutil/nvmutil.c
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-03 17:09:33 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-03 17:09:33 +0000
commit8faa36eb64d82e23956e871ae10ed8bb0ff1d8ad (patch)
tree3039276cfe11dad669862f7acad131b27284c78a /util/nvmutil/nvmutil.c
parent86665c9d22c7f79051a09aaec092111a3882b76d (diff)
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>
Diffstat (limited to 'util/nvmutil/nvmutil.c')
-rw-r--r--util/nvmutil/nvmutil.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index cab2a707..b58e6895 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -122,6 +122,8 @@ main(int argc, char *argv[])
(*cmd)();
write_gbe();
+ err_if(close(fd) == -1);
+
err_if((errno != 0) && (cmd != cmd_dump));
return errno ? EXIT_FAILURE : EXIT_SUCCESS;
}
@@ -520,21 +522,25 @@ write_gbe(void)
{
int p;
- if (flags != O_RDONLY)
- for (p = 0; p < 2; p++)
- if (part_modified[p])
- write_gbe_part(p);
- err_if(close(fd) == -1);
+ if (flags == O_RDONLY)
+ return;
+
+ for (p = 0; p < 2; p++) {
+ if (part_modified[p])
+ write_gbe_part(p);
+ }
}
static void
write_gbe_part(int p)
{
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),
"Can't write %d b to '%s' p%d", SIZE_4KB, fname, p);
+ }
}
static void