virtio-devices: pmem: Avoid panic and propagate errors properly

Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
Bo Chen 2022-09-12 14:48:48 -07:00 committed by Bo Chen
parent 4cc3bdba9f
commit 522e32219c

View File

@ -90,6 +90,8 @@ enum Error {
BufferLengthTooSmall,
#[error("Invalid request")]
InvalidRequest,
#[error("Failed adding used index: {0}")]
QueueAddUsed(virtio_queue::Error),
}
#[derive(Debug, PartialEq, Eq)]
@ -197,7 +199,7 @@ impl PmemEpollHandler {
self.queue
.add_used(desc_chain.memory(), desc_chain.head_index(), len)
.unwrap();
.map_err(Error::QueueAddUsed)?;
used_descs = true;
}