diff --git a/src/ioctls/system.rs b/src/ioctls/system.rs index 07949466..84e1353b 100644 --- a/src/ioctls/system.rs +++ b/src/ioctls/system.rs @@ -221,9 +221,12 @@ impl Kvm { /// ``` /// pub fn get_max_vcpus(&self) -> usize { - match self.check_extension_int(Cap::MaxVcpus) { - 0 => self.get_nr_vcpus(), - x => x as usize, + let v = self.check_extension_int(Cap::MaxVcpus); + + if v <= 0 { + self.get_nr_vcpus() + } else { + v as usize } } @@ -242,9 +245,12 @@ impl Kvm { /// ``` /// pub fn get_max_vcpu_id(&self) -> usize { - match self.check_extension_int(Cap::MaxVcpuId) { - 0 => self.get_max_vcpus(), - x => x as usize, + let v = self.check_extension_int(Cap::MaxVcpuId); + + if v <= 0 { + self.get_max_vcpus() + } else { + v as usize } }