Skip to content

Commit ea9e66b

Browse files
misc(kernel): make clippy happier!
Signed-off-by: Anhad Singh <[email protected]>
1 parent 36028c7 commit ea9e66b

File tree

30 files changed

+216
-179
lines changed

30 files changed

+216
-179
lines changed

src/Cargo.lock

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/aero_kernel/src/acpi/madt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ impl Iterator for MadtIterator {
106106
while self.current < self.limit {
107107
unsafe {
108108
let entry_pointer = self.current;
109-
let header = *(self.current as *const EntryHeader);
109+
let header = *self.current.cast::<EntryHeader>();
110110

111111
self.current = self.current.offset(header.length as isize);
112112

113113
let item = match header.entry_type {
114-
0 => MadtEntry::LocalApic(&*(entry_pointer as *const MadtLocalApic)),
115-
1 => MadtEntry::IoApic(&*(entry_pointer as *const IoApicHeader)),
116-
2 => MadtEntry::IntSrcOverride(&*(entry_pointer as *const MadtIntSrcOverride)),
114+
0 => MadtEntry::LocalApic(&*entry_pointer.cast::<MadtLocalApic>()),
115+
1 => MadtEntry::IoApic(&*entry_pointer.cast::<IoApicHeader>()),
116+
2 => MadtEntry::IntSrcOverride(&*entry_pointer.cast::<MadtIntSrcOverride>()),
117117

118118
0x10..=0x7f => continue,
119119
0x80..=0xff => continue,

src/aero_kernel/src/arch/x86_64/controlregs.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use crate::mem::paging::{PhysAddr, PhysFrame, VirtAddr};
1919

2020
bitflags::bitflags! {
2121
/// Controls cache settings for the level 4 page table.
22+
#[derive(Debug, Copy, Clone)]
23+
#[repr(transparent)]
2224
pub struct Cr3Flags: u64 {
2325
/// Use a writethrough cache policy for the P4 table (else a writeback policy is used).
2426
const PAGE_LEVEL_WRITETHROUGH = 1 << 3;
@@ -29,6 +31,8 @@ bitflags::bitflags! {
2931

3032
bitflags::bitflags! {
3133
/// Controls cache settings for the level 4 page table.
34+
#[derive(Debug, Copy, Clone)]
35+
#[repr(transparent)]
3236
pub struct Cr4Flags: u64 {
3337
/// Enables hardware-supported performance enhancements for software running in
3438
/// virtual-8086 mode.
@@ -86,6 +90,8 @@ bitflags::bitflags! {
8690

8791
bitflags::bitflags! {
8892
/// Configuration flags of the [`Cr0`] register.
93+
#[derive(Debug, Copy, Clone)]
94+
#[repr(transparent)]
8995
pub struct Cr0Flags: u64 {
9096
/// Enables protected mode.
9197
const PROTECTED_MODE_ENABLE = 1;
@@ -184,7 +190,7 @@ bitflags::bitflags! {
184190
}
185191

186192
bitflags::bitflags! {
187-
#[derive(Debug)]
193+
#[derive(Debug, Copy, Clone)]
188194
pub struct MxCsr: u32 {
189195
const INVALID_OPERATION = 1 << 0;
190196
const DENORMAL = 1 << 1;
@@ -212,6 +218,7 @@ bitflags::bitflags! {
212218
/// For MPX, [`BNDREG`](XCr0Flags::BNDREG) and [`BNDCSR`](XCr0Flags::BNDCSR) must be set/unset simultaneously.
213219
/// For AVX-512, [`OPMASK`](XCr0Flags::OPMASK), [`ZMM_HI256`](XCr0Flags::ZMM_HI256), and [`HI16_ZMM`](XCr0Flags::HI16_ZMM)
214220
/// must be set/unset simultaneously.
221+
#[derive(Debug, Copy, Clone)]
215222
#[repr(transparent)]
216223
pub struct XCr0Flags: u64 {
217224
/// Enables using the x87 FPU state

src/aero_kernel/src/arch/x86_64/gdt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use core::ptr::addr_of;
3131
use alloc::alloc::alloc_zeroed;
3232

3333
bitflags::bitflags! {
34+
#[derive(Debug, Copy, Clone)]
3435
struct GdtEntryFlags: u8 {
3536
const PROTECTED_MODE = 1 << 6;
3637
const LONG_MODE = 1 << 5;

src/aero_kernel/src/arch/x86_64/task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl ArchTask {
367367
pub fn exec(
368368
&mut self,
369369
vm: &Vm,
370-
executable: DirCacheItem,
370+
executable: &DirCacheItem,
371371

372372
argv: Option<ExecArgs>,
373373
envv: Option<ExecArgs>,

src/aero_kernel/src/drivers/block/nvme/mod.rs

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,13 @@ impl<'a> Namespace<'a> {
233233
assert!(size_bytes != 0);
234234

235235
let blocks = size_bytes.div_ceil(self.block_size);
236-
let mut read_cmd = ReadWriteCommand::default();
237-
238-
read_cmd.opcode = opcode as u8;
239-
read_cmd.nsid = self.nsid;
240-
read_cmd.start_lba = sector as u64;
241-
read_cmd.length = (blocks - 1) as u16;
236+
let mut read_cmd = ReadWriteCommand {
237+
opcode: opcode as u8,
238+
nsid: self.nsid,
239+
start_lba: sector as u64,
240+
length: (blocks - 1) as u16,
241+
..Default::default()
242+
};
242243

243244
if size_bytes > Size4KiB::SIZE as usize {
244245
// The data cannot fit in 8KiB frames, so we need to use
@@ -338,13 +339,18 @@ impl<'a> Controller<'a> {
338339
registers.set_enable(true)?;
339340

340341
let identity = Dma::<IdentifyController>::zeroed();
341-
let mut identify_command = IdentifyCommand::default();
342342

343-
identify_command.opcode = AdminOpcode::Identify as u8;
344-
identify_command.cns = IdentifyCns::Controller as u8;
345-
identify_command.data_ptr.prp1 = identity.addr().as_u64();
346-
347-
admin.submit_command(identify_command);
343+
// TODO(andypython): builder pattern for building a command? We also shouldn't be required
344+
// to manually fill in the `opcode` field.
345+
admin.submit_command(IdentifyCommand {
346+
opcode: AdminOpcode::Identify as u8,
347+
cns: IdentifyCns::Controller as u8,
348+
data_ptr: DataPointer {
349+
prp1: identity.addr().as_u64(),
350+
..Default::default()
351+
},
352+
..Default::default()
353+
});
348354

349355
log::trace!(
350356
"nvme: identifed controller (vendor={}, subsystem_vendor={})",
@@ -355,27 +361,25 @@ impl<'a> Controller<'a> {
355361
// Create and initialize the I/O queues.
356362
let io_queue = QueuePair::new(registers, queue_size)?;
357363

358-
let mut io_cq_cmd = CreateCQCommand::default();
359-
360-
io_cq_cmd.opcode = AdminOpcode::CreateCq as u8;
361-
io_cq_cmd.prp1 = io_queue.completion_addr().as_u64();
362-
io_cq_cmd.cqid = io_queue.id();
363-
io_cq_cmd.q_size = (io_queue.len() - 1) as u16;
364-
io_cq_cmd.irq_vector = 0;
365-
io_cq_cmd.cq_flags = CommandFlags::QUEUE_PHYS_CONTIG.bits();
366-
367-
admin.submit_command(io_cq_cmd);
368-
369-
let mut io_sq_cmd = CreateSQCommand::default();
370-
371-
io_sq_cmd.opcode = AdminOpcode::CreateSq as u8;
372-
io_sq_cmd.prp1 = io_queue.submission_addr().as_u64();
373-
io_sq_cmd.cqid = io_queue.id();
374-
io_sq_cmd.sqid = io_queue.id();
375-
io_sq_cmd.q_size = (io_queue.len() - 1) as u16;
376-
io_sq_cmd.sq_flags = CommandFlags::QUEUE_PHYS_CONTIG.bits();
364+
admin.submit_command(CreateCQCommand {
365+
opcode: AdminOpcode::CreateCq as u8,
366+
prp1: io_queue.completion_addr().as_u64(),
367+
cqid: io_queue.id(),
368+
q_size: (io_queue.len() - 1) as u16,
369+
irq_vector: 0,
370+
cq_flags: CommandFlags::QUEUE_PHYS_CONTIG.bits(),
371+
..Default::default()
372+
});
377373

378-
admin.submit_command(io_sq_cmd);
374+
admin.submit_command(CreateSQCommand {
375+
opcode: AdminOpcode::CreateSq as u8,
376+
prp1: io_queue.submission_addr().as_u64(),
377+
cqid: io_queue.id(),
378+
sqid: io_queue.id(),
379+
q_size: (io_queue.len() - 1) as u16,
380+
sq_flags: CommandFlags::QUEUE_PHYS_CONTIG.bits(),
381+
..Default::default()
382+
});
379383

380384
let shift = 12 + registers.capability.mpsmin() as usize;
381385
let max_transfer_shift = if identity.mdts != 0 {
@@ -395,13 +399,16 @@ impl<'a> Controller<'a> {
395399
// Discover and initialize the namespaces.
396400
let nsids = {
397401
let nsid_list = Dma::<u32>::new_uninit_slice(this.identity.nn as usize);
398-
let mut nsid_command = IdentifyCommand::default();
399402

400-
nsid_command.opcode = AdminOpcode::Identify as u8;
401-
nsid_command.cns = IdentifyCns::ActivateList as u8;
402-
nsid_command.data_ptr.prp1 = nsid_list.addr().as_u64();
403-
404-
this.admin.lock().submit_command(nsid_command);
403+
this.admin.lock().submit_command(IdentifyCommand {
404+
opcode: AdminOpcode::Identify as u8,
405+
cns: IdentifyCns::ActivateList as u8,
406+
data_ptr: DataPointer {
407+
prp1: nsid_list.addr().as_u64(),
408+
..Default::default()
409+
},
410+
..Default::default()
411+
});
405412

406413
// SAFETY: The list is initialized above.
407414
unsafe { nsid_list.assume_init() }
@@ -416,14 +423,17 @@ impl<'a> Controller<'a> {
416423
}
417424

418425
let identity = Dma::<IdentifyNamespace>::zeroed();
419-
let mut identify_command = IdentifyCommand::default();
420-
421-
identify_command.opcode = AdminOpcode::Identify as u8;
422-
identify_command.cns = IdentifyCns::Namespace as u8;
423-
identify_command.nsid = nsid;
424-
identify_command.data_ptr.prp1 = identity.addr().as_u64();
425426

426-
this.admin.lock().submit_command(identify_command);
427+
this.admin.lock().submit_command(IdentifyCommand {
428+
opcode: AdminOpcode::Identify as u8,
429+
cns: IdentifyCns::Namespace as u8,
430+
nsid,
431+
data_ptr: DataPointer {
432+
prp1: identity.addr().as_u64(),
433+
..Default::default()
434+
},
435+
..Default::default()
436+
});
427437

428438
let blocks = identity.nsze as usize;
429439
let block_size = 1 << identity.lbaf[(identity.flbas & 0b11111) as usize].ds;

src/aero_kernel/src/drivers/block/nvme/queue.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use core::cell::UnsafeCell;
2-
use core::ptr;
32
use core::sync::atomic::{AtomicU16, Ordering};
43

54
use crate::mem::paging::PhysAddr;

src/aero_kernel/src/drivers/e1000.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ impl NetworkDriver for Device {
613613
loop {
614614
let mut e1000 = self.e1000.lock_irq();
615615
if let Some(data) = e1000.recv() {
616-
self.wq.remove(task);
616+
self.wq.remove(&task);
617617
return data;
618618
} else {
619619
drop(e1000);

0 commit comments

Comments
 (0)