Skip to content

Commit

Permalink
xen: remove unwraps in listen
Browse files Browse the repository at this point in the history
  • Loading branch information
Wenzel committed Dec 20, 2020
1 parent f855d41 commit d484b70
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/driver/xen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl Introspectable for Xen {

fn listen(&mut self, timeout: u32) -> Result<Option<Event>, Box<dyn Error>> {
let mut fds: [PollFd; 1] = [self.evtchn_pollfd];
let event: Option<Event> = match poll(&mut fds, timeout.try_into().unwrap()).unwrap() {
let event: Option<Event> = match poll(&mut fds, timeout.try_into()?)? {
0 => {
// timeout. no file descriptors were ready
None
Expand Down Expand Up @@ -366,8 +366,8 @@ impl Introspectable for Xen {
if req.version != VM_EVENT_INTERFACE_VERSION {
panic!("version mismatch");
}
let xen_event_type = (self.xc.get_event_type(req)).unwrap();
let vcpu: u32 = req.vcpu_id.try_into().unwrap();
let xen_event_type = (self.xc.get_event_type(req))?;
let vcpu: u32 = req.vcpu_id.try_into()?;
let event_type: EventType = match xen_event_type {
XenEventType::Cr { cr_type, new, old } => EventType::Cr {
cr_type: match cr_type {
Expand All @@ -389,10 +389,10 @@ impl Introspectable for Xen {
};
// associate VCPU => vm_event_request_t
// to find it in reply_event()
let vcpu_index: usize = vcpu.try_into().unwrap();
let vcpu_index: usize = vcpu.try_into()?;
self.vec_events[vcpu_index] = Some(req);
Some(Event {
vcpu: vcpu.try_into().unwrap(),
vcpu: vcpu.try_into()?,
kind: event_type,
})
}
Expand All @@ -413,7 +413,7 @@ impl Introspectable for Xen {
EventReplyType::Continue => VM_EVENT_FLAG_VCPU_PAUSED,
};
// get the request back
let vcpu_index: usize = event.vcpu.try_into().unwrap();
let vcpu_index: usize = event.vcpu.try_into()?;
let req: vm_event_request_t = mem::replace(&mut self.vec_events[vcpu_index], None).unwrap();
let mut rsp: vm_event_response_t =
unsafe { mem::MaybeUninit::<vm_event_response_t>::zeroed().assume_init() };
Expand Down

0 comments on commit d484b70

Please sign in to comment.