util/nvmutil: simplify nr/nw error handling

when nf and nr/nw are not the same, we know there
is an error condition, so defer to the following err()
call, but use ERR() there instead of hardcoding use
of ECANCELED.

this actually improves the error handling, by being
more verbose, while reducing the amount of logic.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-02-23 09:50:26 +00:00
parent 4473179300
commit 35d8d0993f
+2 -4
View File
@@ -216,13 +216,12 @@ readGbe(void)
continue;
ssize_t nr = pread(fd, (uint8_t *) gbe[p], nf, p * partsize);
err_if(nr == -1);
if (nr == nf) {
swap(p); /* handle big-endian host CPU */
continue;
}
err(errno == ECANCELED,
err(ERR(),
"%ld bytes read from '%s' part %d, expected %ld bytes\n",
nr, filename, p, nf);
}
@@ -425,11 +424,10 @@ writeGbe(void)
swap(p); /* swap bytes on big-endian host CPUs */
ssize_t nw = pwrite(fd, (uint8_t *) gbe[p], nf, p * partsize);
err_if(nw == -1);
if (nw == nf)
continue;
err(errno == ECANCELED,
err(ERR(),
"%ld bytes written to '%s' part %d, expected %ld bytes\n",
nw, filename, p, nf);
}