Skip to content

Commit 0905a42

Browse files
committed
fix(virtq): make clippy happy
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
1 parent 0c36e87 commit 0905a42

5 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/hyperlight_common/src/virtq/buffer.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,22 @@ impl<F: FnOnce(Allocation)> AllocGuard<F> {
139139
}
140140

141141
pub fn release(mut self) -> Allocation {
142-
self.0.take().unwrap().0
142+
// Safety: AllocGuard is always constructed with Some, and release is only called once
143+
self.0.take().map(|(alloc, _)| alloc).unwrap_or_else(|| {
144+
unreachable!("AllocGuard::release called on dismissed guard")
145+
})
143146
}
144147
}
145148

146149
impl<F: FnOnce(Allocation)> core::ops::Deref for AllocGuard<F> {
147150
type Target = Allocation;
148151

149152
fn deref(&self) -> &Allocation {
150-
&self.0.as_ref().unwrap().0
153+
// Safety: AllocGuard is always constructed with Some, and the inner value is only
154+
// taken by release() or Drop.
155+
&self.0.as_ref().unwrap_or_else(|| {
156+
unreachable!("AllocGuard::deref called on dismissed guard")
157+
}).0
151158
}
152159
}
153160

src/hyperlight_common/src/virtq/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ impl From<BufferElement> for Allocation {
351351
}
352352

353353
const _: () = {
354+
#[allow(clippy::unwrap_used)]
354355
const fn verify_layout(num_descs: usize) {
355356
let base = 0x1000u64;
356357

src/hyperlight_common/src/virtq/producer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@ where
519519
self.inner.reset_prefilled(&ids);
520520

521521
let addrs: SmallVec<[u64; 64]> = (0..prefill_count)
522-
.map(|i| self.pool.slot_addr(i).expect("prefill_count <= pool count"))
523-
.collect();
522+
.map(|i| self.pool.slot_addr(i).ok_or(VirtqError::InvalidState))
523+
.collect::<Result<_, _>>()?;
524524

525525
self.pool
526526
.restore_allocated(&addrs)

src/hyperlight_common/src/virtq/ring.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,6 @@ pub fn ring_need_event(event_idx: u16, new: u16, old: u16) -> bool {
12761276
new.wrapping_sub(event_idx).wrapping_sub(1) < new.wrapping_sub(old)
12771277
}
12781278

1279-
12801279
impl From<&Descriptor> for BufferElement {
12811280
fn from(desc: &Descriptor) -> Self {
12821281
BufferElement {

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,8 +1718,8 @@ mod tests {
17181718

17191719
for (name, heap_size) in test_cases {
17201720
let mut cfg = SandboxConfiguration::default();
1721-
cfg.set_heap_size(128 * 1024);
1722-
cfg.set_scratch_size(0x100000);
1721+
cfg.set_heap_size(heap_size);
1722+
cfg.set_scratch_size(heap_size as usize + 0x100000);
17231723

17241724
let path = simple_guest_as_string().unwrap();
17251725
let sbox = UninitializedSandbox::new(GuestBinary::FilePath(path), Some(cfg))

0 commit comments

Comments
 (0)