summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-10 06:17:04 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-10 06:17:04 +0000
commit90fada0a2399e11251ec0180a8f4075de8163b6c (patch)
treedf230c371e47fdb5fc6ea114d3cdb23a1621010b /util
parent2fda988da6e5f70da30d350ca9253f0d15008fc7 (diff)
util/nvmutil: explain errval handling in err()
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
-rw-r--r--util/nvmutil/nvmutil.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index d800ea39..caa03e28 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -1373,6 +1373,21 @@ rw_file_exact(int fd, uint8_t *mem, size_t len,
static void
err(int nvm_errval, const char *msg, ...)
{
+ /*
+ * We need to ensure that files are closed
+ * on exit, including error exits. This
+ * would otherwise recurse, because the
+ * close_files() function also calls err(),
+ * but with -1 on nvm_errval. It's the only
+ * one that does this.
+ *
+ * Since the errval is for setting errno, -1
+ * would be incorrect. Therefore, set_err()
+ * avoids overriding errno if the given value
+ * is negative.
+ *
+ * Be careful modifying err() and close_files().
+ */
if (nvm_errval != -1)
close_files();