virtio-devices: rng: correctly indicate number of bytes written
Reads from the random file may only be partial, e.g., if the random file is an ordinary text
file. When that happens, the device needs to signal to the driver that only parts of the buffer have
been overwritten.
@@ -58,17 +58,13 @@ impl RngEpollHandler {
// Drivers can only read from the random device.
if desc.is_write_only() {
// Fill the read with data from the random device on the host.
- if desc_chain
- .memory()
- .read_from(
+ if let Ok(number_of_bytes) = desc_chain.memory().read_from(
desc.addr()
.translate_gva(self.access_platform.as_ref(), desc.len() as usize),
&mut self.random_file,
desc.len() as usize,
- )
- .is_ok()
- {
- len = desc.len();
+ ) {
+ len = number_of_bytes as u32;
}
}
