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 <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/939868
Reviewed-by: Zach Reizner <zachr@chromium.org>
This commit is contained in:
Dmitry Torokhov 2018-02-27 10:26:34 -08:00 committed by chrome-bot
parent 8283248a60
commit 93b00ecca7

View file

@ -299,7 +299,7 @@ impl Vm {
self.mem_slot_gaps.push(-(slot as i32)); self.mem_slot_gaps.push(-(slot as i32));
Ok(entry.remove()) Ok(entry.remove())
} }
_ => Err(Error::new(-ENOENT)) _ => Err(Error::new(ENOENT))
} }
} }
@ -314,7 +314,7 @@ impl Vm {
Some(mmap) => { Some(mmap) => {
// Ensures that there are as many bytes in dirty_log as there are pages in the 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() { 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 { let mut dirty_log_kvm = kvm_dirty_log {
slot, slot,
@ -327,7 +327,7 @@ impl Vm {
let ret = unsafe { ioctl_with_ref(self, KVM_GET_DIRTY_LOG(), &dirty_log_kvm) }; let ret = unsafe { ioctl_with_ref(self, KVM_GET_DIRTY_LOG(), &dirty_log_kvm) };
if ret == 0 { Ok(()) } else { errno_result() } if ret == 0 { Ok(()) } else { errno_result() }
} }
_ => Err(Error::new(-ENOENT)), _ => Err(Error::new(ENOENT)),
} }
} }