Skip to content

Commit ea13cdf

Browse files
committed
xen: remove unwraps in listen
1 parent 4c13f32 commit ea13cdf

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/driver/xen.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl Introspectable for Xen {
329329

330330
fn listen(&mut self, timeout: u32) -> Result<Option<Event>, Box<dyn Error>> {
331331
let mut fds: [PollFd; 1] = [self.evtchn_pollfd];
332-
let event: Option<Event> = match poll(&mut fds, timeout.try_into().unwrap()).unwrap() {
332+
let event: Option<Event> = match poll(&mut fds, timeout.try_into()?)? {
333333
0 => {
334334
// timeout. no file descriptors were ready
335335
None
@@ -356,7 +356,7 @@ impl Introspectable for Xen {
356356
}
357357
// unmask
358358
self.xev
359-
.xenevtchn_unmask(pending_event_port.try_into().unwrap())?;
359+
.xenevtchn_unmask(pending_event_port.try_into()?)?;
360360
}
361361
};
362362
let back_ring_ptr = &mut self.back_ring;
@@ -367,8 +367,8 @@ impl Introspectable for Xen {
367367
if req.version != VM_EVENT_INTERFACE_VERSION {
368368
panic!("version mismatch");
369369
}
370-
let xen_event_type = (self.xc.get_event_type(req)).unwrap();
371-
let vcpu: u32 = req.vcpu_id.try_into().unwrap();
370+
let xen_event_type = (self.xc.get_event_type(req))?;
371+
let vcpu: u32 = req.vcpu_id.try_into()?;
372372
let event_type: EventType = match xen_event_type {
373373
XenEventType::Cr { cr_type, new, old } => EventType::Cr {
374374
cr_type: match cr_type {
@@ -390,10 +390,10 @@ impl Introspectable for Xen {
390390
};
391391
// associate VCPU => vm_event_request_t
392392
// to find it in reply_event()
393-
let vcpu_index: usize = vcpu.try_into().unwrap();
393+
let vcpu_index: usize = vcpu.try_into()?;
394394
self.vec_events[vcpu_index] = Some(req);
395395
Some(Event {
396-
vcpu: vcpu.try_into().unwrap(),
396+
vcpu: vcpu.try_into()?,
397397
kind: event_type,
398398
})
399399
}
@@ -414,7 +414,7 @@ impl Introspectable for Xen {
414414
EventReplyType::Continue => VM_EVENT_FLAG_VCPU_PAUSED,
415415
};
416416
// get the request back
417-
let vcpu_index: usize = event.vcpu.try_into().unwrap();
417+
let vcpu_index: usize = event.vcpu.try_into()?;
418418
let req: vm_event_request_t = mem::replace(&mut self.vec_events[vcpu_index], None).unwrap();
419419
let mut rsp: vm_event_response_t =
420420
unsafe { mem::MaybeUninit::<vm_event_response_t>::zeroed().assume_init() };

0 commit comments

Comments
 (0)