Skip to content

Commit 72e188d

Browse files
Manciukicbchalios
authored andcommitted
fix(iovec): do not return error if some bytes were read
As in the previous commit, the same erroneous pattern is present also in write_volatile_at. Fix it there as well. Signed-off-by: Riccardo Mancini <mancio@amazon.com>
1 parent 8e74e7d commit 72e188d

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/vmm/src/devices/virtio/iovec.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -459,23 +459,25 @@ impl<const L: u16> IoVecBufferMut<L> {
459459
slice = slice.subslice(0, len)?;
460460
}
461461

462-
let bytes_read = loop {
462+
match loop {
463463
match src.read_volatile(&mut slice) {
464464
Err(VolatileMemoryError::IOError(err))
465-
if err.kind() == ErrorKind::Interrupted =>
466-
{
467-
continue;
468-
}
469-
Ok(bytes_read) => break bytes_read,
470-
Err(volatile_memory_error) => return Err(volatile_memory_error),
465+
if err.kind() == ErrorKind::Interrupted => {}
466+
result => break result,
471467
}
472-
};
473-
total_bytes_read += bytes_read;
468+
} {
469+
Ok(bytes_read) => {
470+
total_bytes_read += bytes_read;
474471

475-
if bytes_read < slice.len() {
476-
break;
472+
if bytes_read < slice.len() {
473+
break;
474+
}
475+
len -= bytes_read;
476+
}
477+
// exit successfully if we previously managed to read some bytes
478+
Err(_) if total_bytes_read > 0 => break,
479+
Err(err) => return Err(err),
477480
}
478-
len -= bytes_read;
479481
}
480482

481483
Ok(total_bytes_read)

0 commit comments

Comments
 (0)