Skip to content

Commit b099584

Browse files
committed
virtio: skip redundant memory check
Signed-off-by: ihciah <[email protected]>
1 parent 68e1973 commit b099584

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/vmm/src/devices/virtio/queue.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ pub struct DescriptorChain<'a, M: GuestMemory = GuestMemoryMmap> {
9696
}
9797

9898
impl<'a, M: GuestMemory> DescriptorChain<'a, M> {
99+
/// Creates a new `DescriptorChain` from the given memory and descriptor table.
100+
///
101+
/// Note that the desc_table and queue_size are assumed to be validated by the caller.
99102
fn checked_new(
100103
mem: &'a M,
101104
desc_table: GuestAddress,
@@ -106,8 +109,8 @@ impl<'a, M: GuestMemory> DescriptorChain<'a, M> {
106109
return None;
107110
}
108111

109-
let desc_head = mem.checked_offset(desc_table, (index as usize) * 16)?;
110-
mem.checked_offset(desc_head, 16)?;
112+
// There's no need for checking as we already validated the descriptor table and index bounds.
113+
let desc_head = desc_table.unchecked_add((index as u64) * 16);
111114

112115
// These reads can't fail unless Guest memory is hopelessly broken.
113116
let desc = match mem.read_obj::<Descriptor>(desc_head) {

0 commit comments

Comments
 (0)