Skip to content

Commit 44588fb

Browse files
kernel: more clippy fixes
Signed-off-by: Anhad Singh <[email protected]>
1 parent b6d7c66 commit 44588fb

File tree

13 files changed

+93
-121
lines changed

13 files changed

+93
-121
lines changed

src/aero_kernel/src/arch/x86_64/apic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,12 @@ pub fn io_apic_set_redirect(vec: u8, gsi: u32, flags: u16, status: i32) {
383383
let mut redirect = 0x00;
384384

385385
// Active high(0) or low(1)
386-
if flags & 2 == 1 {
386+
if (flags & (1 << 1)) != 0 {
387387
redirect |= (1 << 13) as u8;
388388
}
389389

390390
// Edge(0) or level(1) triggered
391-
if flags & 8 == 1 {
391+
if (flags & (1 << 3)) != 0 {
392392
redirect |= (1 << 15) as u8;
393393
}
394394

src/aero_kernel/src/drivers/block/ahci.rs

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ impl DmaRequest {
278278
match self.command {
279279
DmaCommand::Read => {
280280
if lba48 {
281-
AtaCommand::AtaCommandReadDmaExt
281+
AtaCommand::ReadDmaExt
282282
} else {
283-
AtaCommand::AtaCommandReadDma
283+
AtaCommand::ReadDma
284284
}
285285
}
286286
}
@@ -295,65 +295,59 @@ impl DmaRequest {
295295
#[derive(Debug, PartialEq, Copy, Clone)]
296296
#[repr(u8)]
297297
pub enum AtaCommand {
298-
AtaCommandWriteDma = 0xCA,
299-
AtaCommandWriteDmaQueued = 0xCC,
300-
AtaCommandWriteMultiple = 0xC5,
301-
AtaCommandWriteSectors = 0x30,
298+
WriteDma = 0xCA,
299+
WriteDmaQueued = 0xCC,
300+
WriteMultiple = 0xC5,
301+
WriteSectors = 0x30,
302302

303-
AtaCommandReadDma = 0xC8,
304-
AtaCommandReadDmaQueued = 0xC7,
305-
AtaCommandReadMultiple = 0xC4,
306-
AtaCommandReadSectors = 0x20,
303+
ReadDma = 0xC8,
304+
ReadDmaQueued = 0xC7,
305+
ReadMultiple = 0xC4,
306+
ReadSectors = 0x20,
307307

308-
AtaCommandWriteDmaExt = 0x35,
309-
AtaCommandWriteDmaQueuedExt = 0x36,
310-
AtaCommandWriteMultipleExt = 0x39,
311-
AtaCommandWriteSectorsExt = 0x34,
308+
WriteDmaExt = 0x35,
309+
WriteDmaQueuedExt = 0x36,
310+
WriteMultipleExt = 0x39,
311+
WriteSectorsExt = 0x34,
312312

313-
AtaCommandReadDmaExt = 0x25,
314-
AtaCommandReadDmaQueuedExt = 0x26,
315-
AtaCommandReadMultipleExt = 0x29,
316-
AtaCommandReadSectorsExt = 0x24,
313+
ReadDmaExt = 0x25,
314+
ReadDmaQueuedExt = 0x26,
315+
ReadMultipleExt = 0x29,
316+
ReadSectorsExt = 0x24,
317317

318-
AtaCommandPacket = 0xA0,
319-
AtaCommandDeviceReset = 0x08,
318+
Packet = 0xA0,
319+
DeviceReset = 0x08,
320320

321-
AtaCommandService = 0xA2,
322-
AtaCommandNop = 0,
323-
AtaCommandNopNopAutopoll = 1,
321+
Service = 0xA2,
322+
Nop = 0,
323+
NopNopAutopoll = 1,
324324

325-
AtaCommandGetMediaStatus = 0xDA,
325+
GetMediaStatus = 0xDA,
326326

327-
AtaCommandFlushCache = 0xE7,
328-
AtaCommandFlushCacheExt = 0xEA,
327+
FlushCache = 0xE7,
328+
FlushCacheExt = 0xEA,
329329

330-
AtaCommandDataSetManagement = 0x06,
330+
DataSetManagement = 0x06,
331331

332-
AtaCommandMediaEject = 0xED,
332+
MediaEject = 0xED,
333333

334-
AtaCommandIdentifyPacketDevice = 0xA1,
335-
AtaCommandIdentifyDevice = 0xEC,
334+
IdentifyPacketDevice = 0xA1,
335+
IdentifyDevice = 0xEC,
336336

337-
AtaCommandSetFeatures = 0xEF,
338-
AtaCommandSetFeaturesEnableReleaseInt = 0x5D,
339-
AtaCommandSetFeaturesEnableServiceInt = 0x5E,
340-
AtaCommandSetFeaturesDisableReleaseInt = 0xDD,
341-
AtaCommandSetFeaturesDisableServiceInt = 0xDE,
337+
SetFeatures = 0xEF,
338+
SetFeaturesEnableReleaseInt = 0x5D,
339+
SetFeaturesEnableServiceInt = 0x5E,
340+
SetFeaturesDisableReleaseInt = 0xDD,
341+
SetFeaturesDisableServiceInt = 0xDE,
342342
}
343343

344344
impl AtaCommand {
345345
pub fn is_lba48(&self) -> bool {
346-
match self {
347-
AtaCommand::AtaCommandReadDmaExt | AtaCommand::AtaCommandWriteDmaExt => true,
348-
_ => false,
349-
}
346+
matches!(self, AtaCommand::ReadDmaExt | AtaCommand::WriteDmaExt)
350347
}
351348

352349
pub fn is_write(&self) -> bool {
353-
match self {
354-
AtaCommand::AtaCommandWriteDmaExt | AtaCommand::AtaCommandWriteDma => true,
355-
_ => false,
356-
}
350+
matches!(self, AtaCommand::WriteDmaExt | AtaCommand::WriteDma)
357351
}
358352
}
359353

@@ -655,8 +649,7 @@ impl HbaPort {
655649
let header = self.cmd_header_at(slot);
656650
let mut flags = header.flags.get();
657651

658-
if command == AtaCommand::AtaCommandWriteDmaExt || command == AtaCommand::AtaCommandWriteDma
659-
{
652+
if command == AtaCommand::WriteDmaExt || command == AtaCommand::WriteDma {
660653
flags.insert(HbaCmdHeaderFlags::W); // If its a write command add the write flag.
661654
} else {
662655
flags.remove(HbaCmdHeaderFlags::W); // If its a read command remove the write flag.
@@ -932,11 +925,10 @@ struct AhciDriver {
932925

933926
impl PciDeviceHandle for AhciDriver {
934927
fn handles(&self, vendor_id: Vendor, device_id: DeviceType) -> bool {
935-
match (vendor_id, device_id) {
936-
(Vendor::Intel, DeviceType::SataController) => true,
937-
938-
_ => false,
939-
}
928+
matches!(
929+
(vendor_id, device_id),
930+
(Vendor::Intel, DeviceType::SataController)
931+
)
940932
}
941933

942934
fn start(&self, header: &PciHeader, _offset_table: &mut OffsetPageTable) {

src/aero_kernel/src/drivers/block/ide/channel.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl IdeChannelData {
121121
self.base.set_drive_select(slave, false, 0);
122122
delay(1000);
123123

124-
self.base.set_command(AtaCommand::AtaCommandIdentifyDevice);
124+
self.base.set_command(AtaCommand::IdentifyDevice);
125125
delay(1000);
126126

127127
let status = self.base.status();
@@ -146,15 +146,7 @@ impl IdeChannelData {
146146
let lm = self.base.lba_mid();
147147
let lh = self.base.lba_hi();
148148

149-
match (lm, lh) {
150-
(0x0, 0x0) => {
151-
return true;
152-
}
153-
154-
_ => {}
155-
}
156-
157-
false
149+
lm == 0 && lh == 0
158150
}
159151

160152
pub fn setup_prdt(&mut self) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl Capability {
103103

104104
#[repr(u32)]
105105
enum CommandSet {
106-
NVM = 0b000,
106+
Nvm = 0b000,
107107
}
108108

109109
const_assert_eq!(core::mem::size_of::<CommandSet>(), 4);
@@ -329,7 +329,7 @@ impl<'a> Controller<'a> {
329329
registers.acq.set(admin.completion_addr().as_u64());
330330

331331
// Set the controller configuration and admin queue base addresses.
332-
registers.cc.set_css(CommandSet::NVM);
332+
registers.cc.set_css(CommandSet::Nvm);
333333
registers.cc.set_ams(ArbitrationMechanism::RoundRobin);
334334
registers.cc.set_iosqes(6); // 64 bytes
335335
registers.cc.set_iocqes(4); // 16 bytes

src/aero_kernel/src/drivers/mouse.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ bitflags::bitflags! {
2929
/// Represents the flags currently set for the mouse.
3030
#[derive(Default)]
3131
pub struct MouseFlags: u8 {
32-
const LEFT_BUTTON = 0b00000001;
33-
const RIGHT_BUTTON = 0b00000010;
34-
const MIDDLE_BUTTON = 0b00000100;
35-
const ALWAYS_ONE = 0b00001000;
36-
const X_SIGN = 0b00010000;
37-
const Y_SIGN = 0b00100000;
38-
const X_OVERFLOW = 0b01000000;
39-
const Y_OVERFLOW = 0b10000000;
32+
const LEFT_BUTTON = 0b0000_0001;
33+
const RIGHT_BUTTON = 0b0000_0010;
34+
const MIDDLE_BUTTON = 0b0000_0100;
35+
const ALWAYS_ONE = 0b0000_1000;
36+
const X_SIGN = 0b0001_0000;
37+
const Y_SIGN = 0b0010_0000;
38+
const X_OVERFLOW = 0b0100_0000;
39+
const Y_OVERFLOW = 0b1000_0000;
4040
}
4141
}
4242

src/aero_kernel/src/drivers/pci.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,8 @@ impl DeviceType {
502502
#[derive(Debug, PartialEq)]
503503
pub enum Vendor {
504504
Intel,
505-
AMD,
506-
NVIDIA,
505+
Amd,
506+
Nvidia,
507507
Qemu,
508508
Unknown(u32),
509509
}
@@ -512,8 +512,8 @@ impl Vendor {
512512
pub fn new(id: u32) -> Self {
513513
match id {
514514
0x8086 => Self::Intel,
515-
0x1022 => Self::AMD,
516-
0x10DE => Self::NVIDIA,
515+
0x1022 => Self::Amd,
516+
0x10DE => Self::Nvidia,
517517
0x1234 => Self::Qemu,
518518
_ => Self::Unknown(id),
519519
}

src/aero_kernel/src/drivers/pty.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,9 @@ impl TerminalDevice for Slave {
181181
buffer.extend_from_slice(&[b'^', c + 0x40]);
182182
};
183183

184-
match *signo {
185-
SIGINT => ctrl(termios.c_cc[VINTR]),
186-
_ => {}
187-
};
184+
if *signo == SIGINT {
185+
ctrl(termios.c_cc[VINTR])
186+
}
188187
}
189188
}
190189
}

src/aero_kernel/src/logger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl log::Log for AeroLogger {
7474
"(tid={}, pid={}) ",
7575
task.tid().as_usize(),
7676
task.pid().as_usize()
77-
)
77+
);
7878
}
7979
}
8080

src/aero_kernel/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#![no_std]
5353
#![no_main]
5454
#![reexport_test_harness_main = "test_main"]
55+
// #![warn(clippy::pedantic)]
5556

5657
#[macro_use]
5758
extern crate aero_proc;

src/aero_kernel/src/mem/paging/mapper.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -530,17 +530,14 @@ impl<'a, P: PageTableFrameMapping> Mapper<Size2MiB> for MappedPageTable<'a, P> {
530530
&mut self,
531531
page: Page<Size2MiB>,
532532
) -> Result<(PhysFrame<Size2MiB>, MapperFlush<Size2MiB>), UnmapError> {
533-
let p4;
534-
535-
if self.level_5_paging_enabled {
533+
let p4 = if self.level_5_paging_enabled {
536534
let p5 = &mut self.page_table;
537535

538-
p4 = self
539-
.page_table_walker
540-
.next_table_mut(&mut p5[page.p5_index()])?;
536+
self.page_table_walker
537+
.next_table_mut(&mut p5[page.p5_index()])?
541538
} else {
542-
p4 = &mut self.page_table;
543-
}
539+
&mut self.page_table
540+
};
544541

545542
let p3 = self
546543
.page_table_walker
@@ -573,17 +570,14 @@ impl<'a, P: PageTableFrameMapping> Mapper<Size2MiB> for MappedPageTable<'a, P> {
573570
page: Page<Size2MiB>,
574571
flags: PageTableFlags,
575572
) -> Result<MapperFlush<Size2MiB>, FlagUpdateError> {
576-
let p4;
577-
578-
if self.level_5_paging_enabled {
573+
let p4 = if self.level_5_paging_enabled {
579574
let p5 = &mut self.page_table;
580575

581-
p4 = self
582-
.page_table_walker
583-
.next_table_mut(&mut p5[page.p5_index()])?;
576+
self.page_table_walker
577+
.next_table_mut(&mut p5[page.p5_index()])?
584578
} else {
585-
p4 = &mut self.page_table;
586-
}
579+
&mut self.page_table
580+
};
587581

588582
let p3 = self
589583
.page_table_walker
@@ -1156,9 +1150,7 @@ impl<'a> OffsetPageTable<'a> {
11561150
i: usize|
11571151
-> Result<(bool, &mut PageTable), MapToError<Size4KiB>> {
11581152
let entry = &mut table[i];
1159-
let created;
1160-
1161-
if !entry.flags().contains(PageTableFlags::PRESENT) {
1153+
let created = if !entry.flags().contains(PageTableFlags::PRESENT) {
11621154
let frame = FRAME_ALLOCATOR
11631155
.allocate_frame()
11641156
.ok_or(MapToError::FrameAllocationFailed)?;
@@ -1170,16 +1162,16 @@ impl<'a> OffsetPageTable<'a> {
11701162
| PageTableFlags::USER_ACCESSIBLE,
11711163
);
11721164

1173-
created = true;
1165+
true
11741166
} else {
11751167
entry.set_flags(
11761168
PageTableFlags::PRESENT
11771169
| PageTableFlags::WRITABLE
11781170
| PageTableFlags::USER_ACCESSIBLE,
11791171
);
11801172

1181-
created = false;
1182-
}
1173+
false
1174+
};
11831175

11841176
let page_table_ptr = {
11851177
let addr = entry.frame().unwrap().start_address().as_hhdm_virt();

0 commit comments

Comments
 (0)