summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-15 01:59:45 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-15 02:01:20 +0000
commit5d95d4dfe93f40ec00a2f0953747b06cd2af0a2a (patch)
treecb9bac8cbcce1fd04b49ed068507bf72f79e8ea5
parentb365781a4c9f650cacb099ded749c2644e236d4b (diff)
util/nvmutil: stricter return in pread
we were returning if verified is not off, but we were not doing the check soon enough. now it's clearer: just after either a reset, or we found out offset doesn't match, we return sooner. otherwise, we read, and we verify again right after. in the old code, we verified twice in a row. this is just more optimal, for error handling. Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--util/nvmutil/nvmutil.c48
1 files changed, 18 insertions, 30 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 55af4395..d510a9ea 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -2077,27 +2077,28 @@ real_pread_pwrite:
* then another thread may have
* changed it. Enabled if
* off_reset is OFF_RESET.
+ *
+ * We do this *once*, on the theory
+ * that nothing is touching it now.
*/
- if (off != verified) {
- if (!off_reset)
- goto err_prw;
+ if (off_reset && off != verified)
+ lseek_loop(fd, off, SEEK_SET,
+ loop_eagain, loop_eintr);
- /*
- * Even if we allow to continue,
- * we still need to reset the
- * offset. If we can't, then
- * we can't recover at all.
- *
- * However, we must preserve
- * errno in that case, so
- * just return immediately.
- */
- if (lseek_loop(fd, off, SEEK_SET,
- loop_eagain, loop_eintr) == (off_t)-1)
+ do {
+ if (off != verified)
return -1;
- }
- do {
+ if (rw_type == IO_PREAD)
+ r = read(fd, mem, nrw);
+ else if (rw_type == IO_PWRITE)
+ r = write(fd, mem, nrw);
+
+ if (rw_over_nrw(r, nrw) == -1) {
+ errno = EIO;
+ break;
+ }
+
/*
* Verify again before I/O
* (even with OFF_ERR)
@@ -2118,19 +2119,6 @@ real_pread_pwrite:
verified = lseek_loop(fd, (off_t)0, SEEK_CUR,
loop_eagain, loop_eintr);
- if (verified != off)
- goto err_prw;
-
- if (rw_type == IO_PREAD)
- r = read(fd, mem, nrw);
- else if (rw_type == IO_PWRITE)
- r = write(fd, mem, nrw);
-
- if (rw_over_nrw(r, nrw) == -1) {
- errno = EIO;
- break;
- }
-
} while (r == -1 &&
(errno == try_err(loop_eintr, EINTR)
|| errno == try_err(loop_eagain, EAGAIN)));