Skip to content

Commit 0de96ce

Browse files
Traistaru Andrei Cristianandreitraistaru
authored andcommitted
Fix clippy errors
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 <atc@amazon.com>
1 parent f67ef5c commit 0de96ce

File tree

29 files changed

+101
-106
lines changed

29 files changed

+101
-106
lines changed

src/arch/src/aarch64/fdt.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn create_memory_node(fdt: &mut FdtWriter, guest_mem: &GuestMemoryMmap) -> Resul
219219
let mem_size = guest_mem.last_addr().raw_value() - super::layout::DRAM_MEM_START + 1;
220220
// See https://github.com/torvalds/linux/blob/master/Documentation/devicetree/booting-without-of.txt#L960
221221
// for an explanation of this.
222-
let mem_reg_prop = &[super::layout::DRAM_MEM_START as u64, mem_size as u64];
222+
let mem_reg_prop = &[super::layout::DRAM_MEM_START, mem_size];
223223

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

245245
if let Some(initrd_config) = initrd {
246-
fdt.property_u64(
247-
"linux,initrd-start",
248-
initrd_config.address.raw_value() as u64,
249-
)?;
246+
fdt.property_u64("linux,initrd-start", initrd_config.address.raw_value())?;
250247
fdt.property_u64(
251248
"linux,initrd-end",
252249
initrd_config.address.raw_value() + initrd_config.size as u64,

src/arch/src/aarch64/gic/gicv3/regs/icc_regs.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,12 @@ static AP_VGIC_ICC_REGS: &[SimpleReg] = &[
5454

5555
impl SimpleReg {
5656
const fn vgic_sys_reg(op0: u64, op1: u64, crn: u64, crm: u64, op2: u64) -> SimpleReg {
57-
let offset = (((op0 as u64) << KVM_REG_ARM64_SYSREG_OP0_SHIFT)
57+
let offset = ((op0 << KVM_REG_ARM64_SYSREG_OP0_SHIFT)
5858
& KVM_REG_ARM64_SYSREG_OP0_MASK as u64)
59-
| (((op1 as u64) << KVM_REG_ARM64_SYSREG_OP1_SHIFT)
60-
& KVM_REG_ARM64_SYSREG_OP1_MASK as u64)
61-
| (((crn as u64) << KVM_REG_ARM64_SYSREG_CRN_SHIFT)
62-
& KVM_REG_ARM64_SYSREG_CRN_MASK as u64)
63-
| (((crm as u64) << KVM_REG_ARM64_SYSREG_CRM_SHIFT)
64-
& KVM_REG_ARM64_SYSREG_CRM_MASK as u64)
65-
| (((op2 as u64) << KVM_REG_ARM64_SYSREG_OP2_SHIFT)
66-
& KVM_REG_ARM64_SYSREG_OP2_MASK as u64);
59+
| ((op1 << KVM_REG_ARM64_SYSREG_OP1_SHIFT) & KVM_REG_ARM64_SYSREG_OP1_MASK as u64)
60+
| ((crn << KVM_REG_ARM64_SYSREG_CRN_SHIFT) & KVM_REG_ARM64_SYSREG_CRN_MASK as u64)
61+
| ((crm << KVM_REG_ARM64_SYSREG_CRM_SHIFT) & KVM_REG_ARM64_SYSREG_CRM_MASK as u64)
62+
| ((op2 << KVM_REG_ARM64_SYSREG_OP2_SHIFT) & KVM_REG_ARM64_SYSREG_OP2_MASK as u64);
6763

6864
SimpleReg::new(offset, 8)
6965
}

src/arch/src/aarch64/regs.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,8 @@ mod tests {
531531
let offset = offset__of!(user_pt_regs, pc);
532532
let regid = arm64_core_reg_id!(KVM_REG_SIZE_U64, offset);
533533
assert!(!is_system_register(regid));
534-
let regid = KVM_REG_ARM64 as u64
535-
| KVM_REG_SIZE_U64 as u64
536-
| u64::from(kvm_bindings::KVM_REG_ARM64_SYSREG);
534+
let regid =
535+
KVM_REG_ARM64 | KVM_REG_SIZE_U64 | u64::from(kvm_bindings::KVM_REG_ARM64_SYSREG);
537536
assert!(is_system_register(regid));
538537
}
539538

src/arch/src/x86_64/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ pub fn configure_system(
135135
if last_addr < end_32bit_gap_start {
136136
add_e820_entry(
137137
&mut params,
138-
himem_start.raw_value() as u64,
138+
himem_start.raw_value(),
139139
// it's safe to use unchecked_offset_from because
140140
// mem_end > himem_start
141-
last_addr.unchecked_offset_from(himem_start) as u64 + 1,
141+
last_addr.unchecked_offset_from(himem_start) + 1,
142142
E820_RAM,
143143
)?;
144144
} else {

src/arch/src/x86_64/regs.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ pub fn setup_regs(vcpu: &VcpuFd, boot_ip: u64) -> std::result::Result<(), SetupR
108108
// made to rsp (i.e. reserving space for local variables or pushing values on to the stack),
109109
// local variables and function parameters are still accessible from a constant offset from
110110
// rbp.
111-
rsp: super::layout::BOOT_STACK_POINTER as u64,
111+
rsp: super::layout::BOOT_STACK_POINTER,
112112
// Starting stack pointer.
113-
rbp: super::layout::BOOT_STACK_POINTER as u64,
113+
rbp: super::layout::BOOT_STACK_POINTER,
114114
// Must point to zero page address per Linux ABI. This is x86_64 specific.
115-
rsi: super::layout::ZERO_PAGE_START as u64,
115+
rsi: super::layout::ZERO_PAGE_START,
116116
..Default::default()
117117
};
118118

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

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

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

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

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

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

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

257-
sregs.cr3 = boot_pml4_addr.raw_value() as u64;
257+
sregs.cr3 = boot_pml4_addr.raw_value();
258258
sregs.cr4 |= X86_CR4_PAE;
259259
sregs.cr0 |= X86_CR0_PG;
260260
Ok(())
@@ -283,7 +283,7 @@ mod tests {
283283
}
284284

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

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

317-
assert_eq!(PML4_START as u64, sregs.cr3);
317+
assert_eq!(PML4_START, sregs.cr3);
318318
assert!(sregs.cr4 & X86_CR4_PAE != 0);
319319
assert!(sregs.cr0 & X86_CR0_PG != 0);
320320
}
@@ -350,9 +350,9 @@ mod tests {
350350
let expected_regs: kvm_regs = kvm_regs {
351351
rflags: 0x0000_0000_0000_0002u64,
352352
rip: 1,
353-
rsp: super::super::layout::BOOT_STACK_POINTER as u64,
354-
rbp: super::super::layout::BOOT_STACK_POINTER as u64,
355-
rsi: super::super::layout::ZERO_PAGE_START as u64,
353+
rsp: super::super::layout::BOOT_STACK_POINTER,
354+
rbp: super::super::layout::BOOT_STACK_POINTER,
355+
rsi: super::super::layout::ZERO_PAGE_START,
356356
..Default::default()
357357
};
358358

@@ -385,7 +385,7 @@ mod tests {
385385
fn test_write_gdt_table() {
386386
// Not enough memory for the gdt table to be written.
387387
let gm = create_guest_mem(Some(BOOT_GDT_OFFSET));
388-
let gdt_table: [u64; BOOT_GDT_MAX as usize] = [
388+
let gdt_table: [u64; BOOT_GDT_MAX] = [
389389
gdt_entry(0, 0, 0), // NULL
390390
gdt_entry(0xa09b, 0, 0xfffff), // CODE
391391
gdt_entry(0xc093, 0, 0xfffff), // DATA
@@ -398,7 +398,7 @@ mod tests {
398398
BOOT_GDT_OFFSET + (mem::size_of::<u64>() * BOOT_GDT_MAX) as u64,
399399
));
400400

401-
let gdt_table: [u64; BOOT_GDT_MAX as usize] = [
401+
let gdt_table: [u64; BOOT_GDT_MAX] = [
402402
gdt_entry(0, 0, 0), // NULL
403403
gdt_entry(0xa09b, 0, 0xfffff), // CODE
404404
gdt_entry(0xc093, 0, 0xfffff), // DATA

src/cpuid/src/transformer/intel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn update_extended_topology_entry(
9898
);
9999
entry
100100
.ecx
101-
.write_bits_in_range(&ecx::LEVEL_NUMBER_BITRANGE, entry.index as u32);
101+
.write_bits_in_range(&ecx::LEVEL_NUMBER_BITRANGE, entry.index);
102102
entry
103103
.ecx
104104
.write_bits_in_range(&ecx::LEVEL_TYPE_BITRANGE, LEVEL_TYPE_CORE);

src/devices/src/virtio/balloon/device.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl Balloon {
258258
if len > max_len {
259259
error!(
260260
"Inflate descriptor has bogus page count {} > {}, skipping.",
261-
len as usize / SIZE_OF_U32,
261+
len / SIZE_OF_U32,
262262
MAX_PAGES_IN_DESC
263263
);
264264

@@ -267,7 +267,7 @@ impl Balloon {
267267
}
268268
// Break loop if `pfn_buffer` will be overrun by adding all pfns from current
269269
// desc.
270-
if MAX_PAGE_COMPACT_BUFFER - pfn_buffer_idx < len as usize / SIZE_OF_U32 {
270+
if MAX_PAGE_COMPACT_BUFFER - pfn_buffer_idx < len / SIZE_OF_U32 {
271271
queue.undo_pop();
272272
break;
273273
}

src/devices/src/virtio/block/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl DiskProperties {
9696
.map_err(Error::BackingFile)?;
9797
let disk_size = disk_image
9898
.seek(SeekFrom::End(0))
99-
.map_err(Error::BackingFile)? as u64;
99+
.map_err(Error::BackingFile)?;
100100

101101
// We only support disk size, which uses the first two words of the configuration space.
102102
// If the image is not a multiple of the sector size, the tail bits are not exposed.

src/devices/src/virtio/block/io/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,13 @@ pub mod tests {
309309
mem.write(&data, addr).unwrap();
310310
assert_sync_execution!(
311311
engine.write(offset, &mem, addr, partial_len, ()),
312-
partial_len as u32
312+
partial_len
313313
);
314314
// Offset read
315315
let mem = create_mem();
316316
assert_sync_execution!(
317317
engine.read(offset, &mem, addr, partial_len, ()),
318-
partial_len as u32
318+
partial_len
319319
);
320320
// Check data
321321
let mut buf = vec![0u8; partial_len as usize];
@@ -371,11 +371,11 @@ pub mod tests {
371371
let addr = GuestAddress(0);
372372
mem.write(&data, addr).unwrap();
373373
assert_queued!(engine.write(offset, &mem, addr, partial_len, ()));
374-
assert_async_execution(&mem, &mut engine, partial_len as u32);
374+
assert_async_execution(&mem, &mut engine, partial_len);
375375
// Offset read
376376
let mem = create_mem();
377377
assert_queued!(engine.read(offset, &mem, addr, partial_len, ()));
378-
assert_async_execution(&mem, &mut engine, partial_len as u32);
378+
assert_async_execution(&mem, &mut engine, partial_len);
379379
// Check data
380380
let mut buf = vec![0u8; partial_len as usize];
381381
mem.read_slice(&mut buf, addr).unwrap();
@@ -387,12 +387,12 @@ pub mod tests {
387387
// Full write
388388
mem.write(&data, GuestAddress(0)).unwrap();
389389
assert_queued!(engine.write(0, &mem, addr, FILE_LEN, ()));
390-
assert_async_execution(&mem, &mut engine, FILE_LEN as u32);
390+
assert_async_execution(&mem, &mut engine, FILE_LEN);
391391

392392
// Full read
393393
let mem = create_mem();
394394
assert_queued!(engine.read(0, &mem, addr, FILE_LEN, ()));
395-
assert_async_execution(&mem, &mut engine, FILE_LEN as u32);
395+
assert_async_execution(&mem, &mut engine, FILE_LEN);
396396
// Check data
397397
let mut buf = vec![0u8; FILE_LEN as usize];
398398
mem.read_slice(&mut buf, GuestAddress(0)).unwrap();

0 commit comments

Comments
 (0)