Skip to content

Commit 2fd74d8

Browse files
committed
Correctly handle error from check_extension_int()
Kvm::check_extension_int() may return negative value as error code, so Kvm::get_max_vcpus() and Kvm::get_max_vcpu_id() should handle the error cases. Signed-off-by: Liu Jiang <[email protected]>
1 parent 577d4eb commit 2fd74d8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/ioctls/system.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,12 @@ impl Kvm {
221221
/// ```
222222
///
223223
pub fn get_max_vcpus(&self) -> usize {
224-
match self.check_extension_int(Cap::MaxVcpus) {
225-
0 => self.get_nr_vcpus(),
226-
x => x as usize,
224+
let v = self.check_extension_int(Cap::MaxVcpus);
225+
226+
if v <= 0 {
227+
self.get_nr_vcpus()
228+
} else {
229+
v as usize
227230
}
228231
}
229232

@@ -242,9 +245,12 @@ impl Kvm {
242245
/// ```
243246
///
244247
pub fn get_max_vcpu_id(&self) -> usize {
245-
match self.check_extension_int(Cap::MaxVcpuId) {
246-
0 => self.get_max_vcpus(),
247-
x => x as usize,
248+
let v = self.check_extension_int(Cap::MaxVcpuId);
249+
250+
if v <= 0 {
251+
self.get_max_vcpus()
252+
} else {
253+
v as usize
248254
}
249255
}
250256

0 commit comments

Comments
 (0)