From 93b00ecca772569727679e5026850810021be1ec Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Tue, 27 Feb 2018 10:26:34 -0800 Subject: [PATCH] kvm: do not use negative error coded for errno-based errors Errors derived from sysem errors delivered via -1 return code/errno should use positive error codes, not negative, in order for them to be recognized by other components. I.e. we should use errno::Error::new(EINVAL) and not -EINVAL. TEST=cargo test --features plugin; cargo test -p kvm BUG=None Change-Id: Ibe91745c36765c64aeab2f6aae5cd0ca8f243a42 Signed-off-by: Dmitry Torokhov Reviewed-on: https://chromium-review.googlesource.com/939868 Reviewed-by: Zach Reizner --- kvm/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs index d87bc76f48..1c75010ea6 100644 --- a/kvm/src/lib.rs +++ b/kvm/src/lib.rs @@ -299,7 +299,7 @@ impl Vm { self.mem_slot_gaps.push(-(slot as i32)); Ok(entry.remove()) } - _ => Err(Error::new(-ENOENT)) + _ => Err(Error::new(ENOENT)) } } @@ -314,7 +314,7 @@ impl Vm { Some(mmap) => { // Ensures that there are as many bytes in dirty_log as there are pages in the mmap. if dirty_log_bitmap_size(mmap.size()) > dirty_log.len() { - return Err(Error::new(-EINVAL)); + return Err(Error::new(EINVAL)); } let mut dirty_log_kvm = kvm_dirty_log { slot, @@ -327,7 +327,7 @@ impl Vm { let ret = unsafe { ioctl_with_ref(self, KVM_GET_DIRTY_LOG(), &dirty_log_kvm) }; if ret == 0 { Ok(()) } else { errno_result() } } - _ => Err(Error::new(-ENOENT)), + _ => Err(Error::new(ENOENT)), } }