mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-24 11:31:15 +02:00
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>
This commit is contained in:
+19
-31
@@ -2077,27 +2077,28 @@ real_pread_pwrite:
|
|||||||
* then another thread may have
|
* then another thread may have
|
||||||
* changed it. Enabled if
|
* changed it. Enabled if
|
||||||
* off_reset is OFF_RESET.
|
* off_reset is OFF_RESET.
|
||||||
|
*
|
||||||
|
* We do this *once*, on the theory
|
||||||
|
* that nothing is touching it now.
|
||||||
*/
|
*/
|
||||||
if (off != verified) {
|
if (off_reset && off != verified)
|
||||||
if (!off_reset)
|
lseek_loop(fd, off, SEEK_SET,
|
||||||
goto err_prw;
|
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)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
if (off != verified)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
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
|
* Verify again before I/O
|
||||||
* (even with OFF_ERR)
|
* (even with OFF_ERR)
|
||||||
@@ -2118,19 +2119,6 @@ real_pread_pwrite:
|
|||||||
verified = lseek_loop(fd, (off_t)0, SEEK_CUR,
|
verified = lseek_loop(fd, (off_t)0, SEEK_CUR,
|
||||||
loop_eagain, loop_eintr);
|
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 &&
|
} while (r == -1 &&
|
||||||
(errno == try_err(loop_eintr, EINTR)
|
(errno == try_err(loop_eintr, EINTR)
|
||||||
|| errno == try_err(loop_eagain, EAGAIN)));
|
|| errno == try_err(loop_eagain, EAGAIN)));
|
||||||
|
|||||||
Reference in New Issue
Block a user