crosvm: Fix clippy related warnings

Ran clippy with features that are enabled downstream. Those features
will be enabled upstream in later cls when crosvm starts building.

BUG=b:213146388
TEST=presubmit

Change-Id: I67cb74127a349b572e573c350d69d1611533d961
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3793690
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Tested-by: Vikram Auradkar <auradkar@google.com>
This commit is contained in:
Vikram Auradkar 2022-07-28 15:42:45 -07:00 committed by crosvm LUCI
parent 4bf124905a
commit 925ba7a1fb
9 changed files with 27 additions and 29 deletions

View file

@ -96,7 +96,7 @@ pub fn add_serial_devices(
com_evt_1_3: &Event,
com_evt_2_4: &Event,
serial_parameters: &BTreeMap<(SerialHardware, u8), SerialParameters>,
serial_jail: Option<Minijail>,
#[cfg_attr(windows, allow(unused_variables))] serial_jail: Option<Minijail>,
) -> std::result::Result<(), DeviceRegistrationError> {
for com_num in 0..=3 {
let com_evt = match com_num {

View file

@ -73,13 +73,12 @@ impl Haxm {
impl Hypervisor for Haxm {
fn check_capability(&self, cap: HypervisorCap) -> bool {
match cap {
HypervisorCap::UserMemory => true,
// under haxm, guests rely on this leaf to calibrate their
// clocksource.
HypervisorCap::CalibratedTscLeafRequired => true,
_ => false,
}
// under haxm, guests rely on this leaf to calibrate their
// clocksource.
matches!(
cap,
HypervisorCap::UserMemory | HypervisorCap::CalibratedTscLeafRequired
)
}
/// Makes a shallow clone of this `Hypervisor`.

View file

@ -531,8 +531,8 @@ impl VcpuX86_64 for HaxmVcpu {
}
// copy values we got from kernel
for i in 0..chunk_size {
chunk[i].value = msr_data.entries[i].value;
for (i, item) in chunk.iter_mut().enumerate().take(chunk_size) {
item.value = msr_data.entries[i].value;
}
}

View file

@ -390,7 +390,7 @@ pub enum Datamatch {
}
/// A reason why a VCPU exited. One of these returns every time `Vcpu::run` is called.
#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub enum VcpuExit {
/// An io instruction needs to be emulated.
/// vcpu handle_io should be called to handle the io operation

View file

@ -349,7 +349,7 @@ impl WhpxVcpu {
index,
safe_virtual_processor: Arc::new(safe_virtual_processor),
vcpu_run_handle_fingerprint: Default::default(),
vm_partition: vm_partition.clone(),
vm_partition,
last_exit_context: Arc::new(Default::default()),
instruction_emulator: Arc::new(instruction_emulator),
tsc_frequency: None,
@ -425,11 +425,8 @@ impl WhpxVcpu {
return Err(Error::new(EINVAL));
}
let success = match id {
// Do nothing, we assume TSC is always invariant
HV_X64_MSR_TSC_INVARIANT_CONTROL => true,
_ => false,
};
// Do nothing, we assume TSC is always invariant
let success = matches!(id, HV_X64_MSR_TSC_INVARIANT_CONTROL);
if !success {
return self.inject_gp_fault();
@ -522,8 +519,8 @@ impl Vcpu for WhpxVcpu {
vm_partition: self.vm_partition.clone(),
last_exit_context: self.last_exit_context.clone(),
instruction_emulator: self.instruction_emulator.clone(),
tsc_frequency: self.tsc_frequency.clone(),
apic_frequency: self.apic_frequency.clone(),
tsc_frequency: self.tsc_frequency,
apic_frequency: self.apic_frequency,
})
}

View file

@ -114,9 +114,9 @@ impl WhpxVm {
Reserved: [0u32; 3],
// HYPERV_CPUID_MIN is the minimum leaf that we need to support returning to the guest
Eax: HYPERV_CPUID_MIN,
Ebx: u32::from_le_bytes(['M' as u8, 'i' as u8, 'c' as u8, 'r' as u8]),
Ecx: u32::from_le_bytes(['o' as u8, 's' as u8, 'o' as u8, 'f' as u8]),
Edx: u32::from_le_bytes(['t' as u8, ' ' as u8, 'H' as u8, 'v' as u8]),
Ebx: u32::from_le_bytes([b'M', b'i', b'c', b'r']),
Ecx: u32::from_le_bytes([b'o', b's', b'o', b'f']),
Edx: u32::from_le_bytes([b't', b' ', b'H', b'v']),
});
// HYPERV_CPUID_FEATURES leaf tells linux which Hyper-V features we support
@ -283,9 +283,11 @@ impl WhpxVm {
delivery: DeliveryMode,
) -> Result<()> {
// The WHV_INTERRUPT_CONTROL does not seem to support the dest_shorthand
let mut interrupt = WHV_INTERRUPT_CONTROL::default();
interrupt.Destination = dest_id as u32;
interrupt.Vector = vector as u32;
let mut interrupt = WHV_INTERRUPT_CONTROL {
Destination: dest_id as u32,
Vector: vector as u32,
..Default::default()
};
interrupt.set_DestinationMode(match dest_mode {
DestinationMode::Physical => {
WHV_INTERRUPT_DESTINATION_MODE_WHvX64InterruptDestinationModePhysical

View file

@ -195,7 +195,7 @@ impl CallbackHandler for Handler {
}
}
fn end_read_from_guest<'a>(&'a mut self) -> io::Result<&'a [u8]> {
fn end_read_from_guest(&mut self) -> io::Result<&[u8]> {
#[cfg(any(feature = "slirp-ring-capture", feature = "slirp-debug"))]
let d = self.start.elapsed();
match self
@ -399,7 +399,7 @@ fn poll<'a>(
) -> Result<(Vec<&'a dyn AsRawDescriptor>, Vec<WSAPOLLFD>)> {
let mut selected_sockets = Vec::with_capacity(sockets.len());
for socket in sockets.iter() {
selected_sockets.push(EventSelectedSocket::new(*socket, &socket_event_handle)?);
selected_sockets.push(EventSelectedSocket::new(*socket, socket_event_handle)?);
}
wait_ctx.clear().map_err(Error::SlirpPollError)?;

View file

@ -151,7 +151,7 @@ pub trait CallbackHandler {
fn begin_read_from_guest(&mut self) -> io::Result<()>;
fn end_read_from_guest<'a>(&'a mut self) -> io::Result<&'a [u8]>;
fn end_read_from_guest(&mut self) -> io::Result<&[u8]>;
}
extern "C" fn write_handler_callback(buf: *const c_void, len: usize, opaque: *mut c_void) -> isize {

View file

@ -143,7 +143,7 @@ impl<R: Req> Endpoint<R> for TubeEndpoint<R> {
fn create_slave_request_endpoint(
&mut self,
files: Option<Vec<File>>,
_files: Option<Vec<File>>,
) -> Result<Box<dyn Endpoint<SlaveReq>>> {
unimplemented!("SET_SLAVE_REQ_FD not supported");
}