util/nvmutil: implement zero-byte r/w timeout

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-12 16:24:36 +00:00
parent 9656e78c3a
commit 303c382eae
+12 -9
View File
@@ -1461,6 +1461,9 @@ rw_file_once(int fd, uint8_t *mem, size_t len,
off_t off, int rw_type, size_t rc) off_t off, int rw_type, size_t rc)
{ {
ssize_t rv; ssize_t rv;
size_t retries_on_zero = 0;
size_t max_retries = 10;
read_again: read_again:
rv = do_rw(fd, mem + rc, len - rc, off + rc, rw_type); rv = do_rw(fd, mem + rc, len - rc, off + rc, rw_type);
@@ -1479,17 +1482,17 @@ read_again:
*/ */
if ((size_t)rv > (len - rc) /* Prevent overflow */ if ((size_t)rv > (len - rc) /* Prevent overflow */
|| rv == 0) { /* Prevent infinite 0-byte loop */ || rv == 0) { /* Prevent infinite 0-byte loop */
if (rv == 0) {
/* /*
* TODO: handle rv == 0 this way: * Fault tolerance against infinite
* re-try a finite number of times, * zero-byte loop: re-try a finite
* based on a counter, that resets * number of times. This mitigates
* on a non-zero read but then returns * otherwise OK but slow filesystems
* like below if the counter reaches * e.g. NFS or slow media.
* the limit. This will retain the
* current safety, while increasing
* robustness e.g. on unreliable NFS
* shares or really slow media.
*/ */
if (retries_on_zero++ < max_retries)
goto read_again;
}
errno = EIO; errno = EIO;
return -1; return -1;
} }