Skip to content

Commit ed66084

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 462e32c commit ed66084

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

coverage_config_x86_64.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"coverage_score": 91.4,
2+
"coverage_score": 90.4,
33
"exclude_path": "",
44
"crate_features": ""
55
}

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)