Skip to content

Commit 22ad768

Browse files
remove redundant use of ? operator
We were previously using return Err(e)? when we wanted to convert from one error type to the error type returned by a specific function. Instead of using the ? operator, we can just call `.into` directly. Signed-off-by: Andreea Florescu <[email protected]>
1 parent a963413 commit 22ad768

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

kernel/src/loader/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ pub fn load_cmdline(
248248
.checked_add(raw_cmdline.len())
249249
.ok_or(CmdlineError::CommandLineOverflow)?; // Extra for null termination.
250250
if end > guest_mem.end_addr() {
251-
return Err(CmdlineError::CommandLineOverflow)?;
251+
return Err(CmdlineError::CommandLineOverflow);
252252
}
253253

254254
guest_mem

vmm/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ impl KvmContext {
441441
// Check that all desired capabilities aer supported.
442442
for capability in capabilities.iter() {
443443
if !kvm.check_extension(*capability) {
444-
Err(Error::KvmCap(*capability))?;
444+
return Err(Error::KvmCap(*capability));
445445
}
446446
}
447447

@@ -1396,7 +1396,7 @@ impl Vmm {
13961396
pub fn start_microvm(&mut self) -> UserResult {
13971397
info!("VMM received instance start command");
13981398
if self.is_instance_initialized() {
1399-
Err(StartMicrovmError::MicroVMAlreadyRunning)?;
1399+
return Err(StartMicrovmError::MicroVMAlreadyRunning.into());
14001400
}
14011401

14021402
let request_ts = TimestampUs {
@@ -1630,7 +1630,7 @@ impl Vmm {
16301630
use VmmActionError::BootSource;
16311631

16321632
if self.is_instance_initialized() {
1633-
Err(BootSource(User, UpdateNotAllowedPostBoot))?;
1633+
return Err(BootSource(User, UpdateNotAllowedPostBoot));
16341634
}
16351635

16361636
let kernel_file =
@@ -1655,15 +1655,15 @@ impl Vmm {
16551655
/// Set the machine configuration of the microVM.
16561656
pub fn set_vm_configuration(&mut self, machine_config: VmConfig) -> UserResult {
16571657
if self.is_instance_initialized() {
1658-
Err(VmConfigError::UpdateNotAllowedPostBoot)?;
1658+
return Err(VmConfigError::UpdateNotAllowedPostBoot.into());
16591659
}
16601660

16611661
if machine_config.vcpu_count == Some(0) {
1662-
Err(VmConfigError::InvalidVcpuCount)?;
1662+
return Err(VmConfigError::InvalidVcpuCount.into());
16631663
}
16641664

16651665
if machine_config.mem_size_mib == Some(0) {
1666-
Err(VmConfigError::InvalidMemorySize)?;
1666+
return Err(VmConfigError::InvalidMemorySize.into());
16671667
}
16681668

16691669
let ht_enabled = machine_config
@@ -1677,7 +1677,7 @@ impl Vmm {
16771677
// If hyperthreading is enabled or is to be enabled in this call
16781678
// only allow vcpu count to be 1 or even.
16791679
if ht_enabled && vcpu_count_value > 1 && vcpu_count_value % 2 == 1 {
1680-
Err(VmConfigError::InvalidVcpuCount)?;
1680+
return Err(VmConfigError::InvalidVcpuCount.into());
16811681
}
16821682

16831683
// Update all the fields that have a new value.
@@ -1698,7 +1698,7 @@ impl Vmm {
16981698
/// Inserts a network device to be attached when the VM starts.
16991699
pub fn insert_net_device(&mut self, body: NetworkInterfaceConfig) -> UserResult {
17001700
if self.is_instance_initialized() {
1701-
Err(NetworkInterfaceError::UpdateNotAllowedPostBoot)?;
1701+
return Err(NetworkInterfaceError::UpdateNotAllowedPostBoot.into());
17021702
}
17031703
self.device_configs
17041704
.network_interface
@@ -1814,7 +1814,7 @@ impl Vmm {
18141814
pub fn rescan_block_device(&mut self, drive_id: &str) -> UserResult {
18151815
// Rescan can only happen after the guest is booted.
18161816
if !self.is_instance_initialized() {
1817-
Err(DriveError::OperationNotAllowedPreBoot)?;
1817+
return Err(DriveError::OperationNotAllowedPreBoot.into());
18181818
}
18191819

18201820
// Safe to unwrap() because mmio_device_manager is initialized in init_devices(), which is
@@ -1846,7 +1846,7 @@ impl Vmm {
18461846
// If the drive_id does not exist, a new Block Device Config is added to the list.
18471847
pub fn insert_block_device(&mut self, block_device_config: BlockDeviceConfig) -> UserResult {
18481848
if self.is_instance_initialized() {
1849-
Err(DriveError::UpdateNotAllowedPostBoot)?;
1849+
return Err(DriveError::UpdateNotAllowedPostBoot.into());
18501850
}
18511851
self.device_configs
18521852
.block

0 commit comments

Comments
 (0)