Skip to content

Commit

Permalink
Fix clippy errors
Browse files Browse the repository at this point in the history
As a result of the Rust toolchain upgrade from 1.65 to 1.66,
several clippy errors appeared (most of them being
clippy::unneccesary_cast). This commit fixes these errors.

Signed-off-by: Traistaru Andrei Cristian <[email protected]>
  • Loading branch information
Traistaru Andrei Cristian authored and andreitraistaru committed Dec 28, 2022
1 parent f67ef5c commit 0de96ce
Show file tree
Hide file tree
Showing 29 changed files with 101 additions and 106 deletions.
7 changes: 2 additions & 5 deletions src/arch/src/aarch64/fdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fn create_memory_node(fdt: &mut FdtWriter, guest_mem: &GuestMemoryMmap) -> Resul
let mem_size = guest_mem.last_addr().raw_value() - super::layout::DRAM_MEM_START + 1;
// See https://github.com/torvalds/linux/blob/master/Documentation/devicetree/booting-without-of.txt#L960
// for an explanation of this.
let mem_reg_prop = &[super::layout::DRAM_MEM_START as u64, mem_size as u64];
let mem_reg_prop = &[super::layout::DRAM_MEM_START, mem_size];

let mem = fdt.begin_node("memory")?;
fdt.property_string("device_type", "memory")?;
Expand All @@ -243,10 +243,7 @@ fn create_chosen_node(
fdt.property_string("bootargs", cmdline_string.as_str())?;

if let Some(initrd_config) = initrd {
fdt.property_u64(
"linux,initrd-start",
initrd_config.address.raw_value() as u64,
)?;
fdt.property_u64("linux,initrd-start", initrd_config.address.raw_value())?;
fdt.property_u64(
"linux,initrd-end",
initrd_config.address.raw_value() + initrd_config.size as u64,
Expand Down
14 changes: 5 additions & 9 deletions src/arch/src/aarch64/gic/gicv3/regs/icc_regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,12 @@ static AP_VGIC_ICC_REGS: &[SimpleReg] = &[

impl SimpleReg {
const fn vgic_sys_reg(op0: u64, op1: u64, crn: u64, crm: u64, op2: u64) -> SimpleReg {
let offset = (((op0 as u64) << KVM_REG_ARM64_SYSREG_OP0_SHIFT)
let offset = ((op0 << KVM_REG_ARM64_SYSREG_OP0_SHIFT)
& KVM_REG_ARM64_SYSREG_OP0_MASK as u64)
| (((op1 as u64) << KVM_REG_ARM64_SYSREG_OP1_SHIFT)
& KVM_REG_ARM64_SYSREG_OP1_MASK as u64)
| (((crn as u64) << KVM_REG_ARM64_SYSREG_CRN_SHIFT)
& KVM_REG_ARM64_SYSREG_CRN_MASK as u64)
| (((crm as u64) << KVM_REG_ARM64_SYSREG_CRM_SHIFT)
& KVM_REG_ARM64_SYSREG_CRM_MASK as u64)
| (((op2 as u64) << KVM_REG_ARM64_SYSREG_OP2_SHIFT)
& KVM_REG_ARM64_SYSREG_OP2_MASK as u64);
| ((op1 << KVM_REG_ARM64_SYSREG_OP1_SHIFT) & KVM_REG_ARM64_SYSREG_OP1_MASK as u64)
| ((crn << KVM_REG_ARM64_SYSREG_CRN_SHIFT) & KVM_REG_ARM64_SYSREG_CRN_MASK as u64)
| ((crm << KVM_REG_ARM64_SYSREG_CRM_SHIFT) & KVM_REG_ARM64_SYSREG_CRM_MASK as u64)
| ((op2 << KVM_REG_ARM64_SYSREG_OP2_SHIFT) & KVM_REG_ARM64_SYSREG_OP2_MASK as u64);

SimpleReg::new(offset, 8)
}
Expand Down
5 changes: 2 additions & 3 deletions src/arch/src/aarch64/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,8 @@ mod tests {
let offset = offset__of!(user_pt_regs, pc);
let regid = arm64_core_reg_id!(KVM_REG_SIZE_U64, offset);
assert!(!is_system_register(regid));
let regid = KVM_REG_ARM64 as u64
| KVM_REG_SIZE_U64 as u64
| u64::from(kvm_bindings::KVM_REG_ARM64_SYSREG);
let regid =
KVM_REG_ARM64 | KVM_REG_SIZE_U64 | u64::from(kvm_bindings::KVM_REG_ARM64_SYSREG);
assert!(is_system_register(regid));
}

Expand Down
4 changes: 2 additions & 2 deletions src/arch/src/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ pub fn configure_system(
if last_addr < end_32bit_gap_start {
add_e820_entry(
&mut params,
himem_start.raw_value() as u64,
himem_start.raw_value(),
// it's safe to use unchecked_offset_from because
// mem_end > himem_start
last_addr.unchecked_offset_from(himem_start) as u64 + 1,
last_addr.unchecked_offset_from(himem_start) + 1,
E820_RAM,
)?;
} else {
Expand Down
32 changes: 16 additions & 16 deletions src/arch/src/x86_64/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ pub fn setup_regs(vcpu: &VcpuFd, boot_ip: u64) -> std::result::Result<(), SetupR
// made to rsp (i.e. reserving space for local variables or pushing values on to the stack),
// local variables and function parameters are still accessible from a constant offset from
// rbp.
rsp: super::layout::BOOT_STACK_POINTER as u64,
rsp: super::layout::BOOT_STACK_POINTER,
// Starting stack pointer.
rbp: super::layout::BOOT_STACK_POINTER as u64,
rbp: super::layout::BOOT_STACK_POINTER,
// Must point to zero page address per Linux ABI. This is x86_64 specific.
rsi: super::layout::ZERO_PAGE_START as u64,
rsi: super::layout::ZERO_PAGE_START,
..Default::default()
};

Expand Down Expand Up @@ -199,7 +199,7 @@ fn write_idt_value(val: u64, guest_mem: &GuestMemoryMmap) -> Result<()> {
}

fn configure_segments_and_sregs(mem: &GuestMemoryMmap, sregs: &mut kvm_sregs) -> Result<()> {
let gdt_table: [u64; BOOT_GDT_MAX as usize] = [
let gdt_table: [u64; BOOT_GDT_MAX] = [
gdt_entry(0, 0, 0), // NULL
gdt_entry(0xa09b, 0, 0xfffff), // CODE
gdt_entry(0xc093, 0, 0xfffff), // DATA
Expand All @@ -212,11 +212,11 @@ fn configure_segments_and_sregs(mem: &GuestMemoryMmap, sregs: &mut kvm_sregs) ->

// Write segments
write_gdt_table(&gdt_table[..], mem)?;
sregs.gdt.base = BOOT_GDT_OFFSET as u64;
sregs.gdt.base = BOOT_GDT_OFFSET;
sregs.gdt.limit = mem::size_of_val(&gdt_table) as u16 - 1;

write_idt_value(0, mem)?;
sregs.idt.base = BOOT_IDT_OFFSET as u64;
sregs.idt.base = BOOT_IDT_OFFSET;
sregs.idt.limit = mem::size_of::<u64>() as u16 - 1;

sregs.cs = code_seg;
Expand All @@ -241,11 +241,11 @@ fn setup_page_tables(mem: &GuestMemoryMmap, sregs: &mut kvm_sregs) -> Result<()>
let boot_pde_addr = GuestAddress(PDE_START);

// Entry covering VA [0..512GB)
mem.write_obj(boot_pdpte_addr.raw_value() as u64 | 0x03, boot_pml4_addr)
mem.write_obj(boot_pdpte_addr.raw_value() | 0x03, boot_pml4_addr)
.map_err(|_| Error::WritePML4Address)?;

// Entry covering VA [0..1GB)
mem.write_obj(boot_pde_addr.raw_value() as u64 | 0x03, boot_pdpte_addr)
mem.write_obj(boot_pde_addr.raw_value() | 0x03, boot_pdpte_addr)
.map_err(|_| Error::WritePDPTEAddress)?;
// 512 2MB entries together covering VA [0..1GB). Note we are assuming
// CPU supports 2MB pages (/proc/cpuinfo has 'pse'). All modern CPUs do.
Expand All @@ -254,7 +254,7 @@ fn setup_page_tables(mem: &GuestMemoryMmap, sregs: &mut kvm_sregs) -> Result<()>
.map_err(|_| Error::WritePDEAddress)?;
}

sregs.cr3 = boot_pml4_addr.raw_value() as u64;
sregs.cr3 = boot_pml4_addr.raw_value();
sregs.cr4 |= X86_CR4_PAE;
sregs.cr0 |= X86_CR0_PG;
Ok(())
Expand Down Expand Up @@ -283,7 +283,7 @@ mod tests {
}

fn read_u64(gm: &GuestMemoryMmap, offset: u64) -> u64 {
let read_addr = GuestAddress(offset as u64);
let read_addr = GuestAddress(offset);
gm.read_obj(read_addr).unwrap()
}

Expand Down Expand Up @@ -314,7 +314,7 @@ mod tests {
assert_eq!((i << 21) + 0x83u64, read_u64(gm, PDE_START + (i * 8)));
}

assert_eq!(PML4_START as u64, sregs.cr3);
assert_eq!(PML4_START, sregs.cr3);
assert!(sregs.cr4 & X86_CR4_PAE != 0);
assert!(sregs.cr0 & X86_CR0_PG != 0);
}
Expand Down Expand Up @@ -350,9 +350,9 @@ mod tests {
let expected_regs: kvm_regs = kvm_regs {
rflags: 0x0000_0000_0000_0002u64,
rip: 1,
rsp: super::super::layout::BOOT_STACK_POINTER as u64,
rbp: super::super::layout::BOOT_STACK_POINTER as u64,
rsi: super::super::layout::ZERO_PAGE_START as u64,
rsp: super::super::layout::BOOT_STACK_POINTER,
rbp: super::super::layout::BOOT_STACK_POINTER,
rsi: super::super::layout::ZERO_PAGE_START,
..Default::default()
};

Expand Down Expand Up @@ -385,7 +385,7 @@ mod tests {
fn test_write_gdt_table() {
// Not enough memory for the gdt table to be written.
let gm = create_guest_mem(Some(BOOT_GDT_OFFSET));
let gdt_table: [u64; BOOT_GDT_MAX as usize] = [
let gdt_table: [u64; BOOT_GDT_MAX] = [
gdt_entry(0, 0, 0), // NULL
gdt_entry(0xa09b, 0, 0xfffff), // CODE
gdt_entry(0xc093, 0, 0xfffff), // DATA
Expand All @@ -398,7 +398,7 @@ mod tests {
BOOT_GDT_OFFSET + (mem::size_of::<u64>() * BOOT_GDT_MAX) as u64,
));

let gdt_table: [u64; BOOT_GDT_MAX as usize] = [
let gdt_table: [u64; BOOT_GDT_MAX] = [
gdt_entry(0, 0, 0), // NULL
gdt_entry(0xa09b, 0, 0xfffff), // CODE
gdt_entry(0xc093, 0, 0xfffff), // DATA
Expand Down
2 changes: 1 addition & 1 deletion src/cpuid/src/transformer/intel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn update_extended_topology_entry(
);
entry
.ecx
.write_bits_in_range(&ecx::LEVEL_NUMBER_BITRANGE, entry.index as u32);
.write_bits_in_range(&ecx::LEVEL_NUMBER_BITRANGE, entry.index);
entry
.ecx
.write_bits_in_range(&ecx::LEVEL_TYPE_BITRANGE, LEVEL_TYPE_CORE);
Expand Down
4 changes: 2 additions & 2 deletions src/devices/src/virtio/balloon/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl Balloon {
if len > max_len {
error!(
"Inflate descriptor has bogus page count {} > {}, skipping.",
len as usize / SIZE_OF_U32,
len / SIZE_OF_U32,
MAX_PAGES_IN_DESC
);

Expand All @@ -267,7 +267,7 @@ impl Balloon {
}
// Break loop if `pfn_buffer` will be overrun by adding all pfns from current
// desc.
if MAX_PAGE_COMPACT_BUFFER - pfn_buffer_idx < len as usize / SIZE_OF_U32 {
if MAX_PAGE_COMPACT_BUFFER - pfn_buffer_idx < len / SIZE_OF_U32 {
queue.undo_pop();
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/devices/src/virtio/block/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl DiskProperties {
.map_err(Error::BackingFile)?;
let disk_size = disk_image
.seek(SeekFrom::End(0))
.map_err(Error::BackingFile)? as u64;
.map_err(Error::BackingFile)?;

// We only support disk size, which uses the first two words of the configuration space.
// If the image is not a multiple of the sector size, the tail bits are not exposed.
Expand Down
12 changes: 6 additions & 6 deletions src/devices/src/virtio/block/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,13 @@ pub mod tests {
mem.write(&data, addr).unwrap();
assert_sync_execution!(
engine.write(offset, &mem, addr, partial_len, ()),
partial_len as u32
partial_len
);
// Offset read
let mem = create_mem();
assert_sync_execution!(
engine.read(offset, &mem, addr, partial_len, ()),
partial_len as u32
partial_len
);
// Check data
let mut buf = vec![0u8; partial_len as usize];
Expand Down Expand Up @@ -371,11 +371,11 @@ pub mod tests {
let addr = GuestAddress(0);
mem.write(&data, addr).unwrap();
assert_queued!(engine.write(offset, &mem, addr, partial_len, ()));
assert_async_execution(&mem, &mut engine, partial_len as u32);
assert_async_execution(&mem, &mut engine, partial_len);
// Offset read
let mem = create_mem();
assert_queued!(engine.read(offset, &mem, addr, partial_len, ()));
assert_async_execution(&mem, &mut engine, partial_len as u32);
assert_async_execution(&mem, &mut engine, partial_len);
// Check data
let mut buf = vec![0u8; partial_len as usize];
mem.read_slice(&mut buf, addr).unwrap();
Expand All @@ -387,12 +387,12 @@ pub mod tests {
// Full write
mem.write(&data, GuestAddress(0)).unwrap();
assert_queued!(engine.write(0, &mem, addr, FILE_LEN, ()));
assert_async_execution(&mem, &mut engine, FILE_LEN as u32);
assert_async_execution(&mem, &mut engine, FILE_LEN);

// Full read
let mem = create_mem();
assert_queued!(engine.read(0, &mem, addr, FILE_LEN, ()));
assert_async_execution(&mem, &mut engine, FILE_LEN as u32);
assert_async_execution(&mem, &mut engine, FILE_LEN);
// Check data
let mut buf = vec![0u8; FILE_LEN as usize];
mem.read_slice(&mut buf, GuestAddress(0)).unwrap();
Expand Down
Loading

0 comments on commit 0de96ce

Please sign in to comment.