Skip to content

Commit b0889d7

Browse files
authored
Merge pull request #1490 from hermit-os/clippy
fix: enable more Clippy lints
2 parents e788313 + d88de47 commit b0889d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+506
-482
lines changed

Cargo.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,33 @@ udp = ["smoltcp", "smoltcp/socket-udp"]
7070
vga = []
7171
vsock = ["pci"]
7272

73+
[lints.rust]
74+
rust_2018_idioms = "warn"
75+
unsafe_op_in_unsafe_fn = "warn"
76+
77+
[lints.clippy]
78+
borrow_as_ptr = "warn"
79+
cast_lossless = "warn"
80+
decimal_literal_representation = "warn"
81+
default_trait_access = "warn"
82+
explicit_deref_methods = "warn"
83+
if_not_else = "warn"
84+
ignored_unit_patterns = "warn"
85+
inconsistent_struct_constructor = "warn"
86+
manual_assert = "warn"
87+
manual_let_else = "warn"
88+
match_wildcard_for_single_variants = "warn"
89+
ptr_as_ptr = "warn"
90+
ptr_cast_constness = "warn"
91+
ref_as_ptr = "warn"
92+
ref_option = "warn"
93+
semicolon_if_nothing_returned = "warn"
94+
separated_literal_suffix = "warn"
95+
string_to_string = "warn"
96+
transmute_ptr_to_ptr = "warn"
97+
uninlined_format_args = "warn"
98+
unreadable_literal = "warn"
99+
73100
[dependencies]
74101
hermit-macro = { path = "hermit-macro" }
75102
virtio = { package = "virtio-spec", version = "0.2", features = ["alloc", "mmio", "nightly", "zerocopy"] }

rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
group_imports = "StdExternalCrate"
22
hard_tabs = true
3+
hex_literal_case = "Lower"
34
imports_granularity = "Module"

src/arch/aarch64/kernel/interrupts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ pub(crate) extern "C" fn do_sync(state: &State) {
175175
let irqid = GicV3::get_and_acknowledge_interrupt().unwrap();
176176
let esr = ESR_EL1.get();
177177
let ec = esr >> 26;
178-
let iss = esr & 0xFFFFFF;
178+
let iss = esr & 0x00ff_ffff;
179179
let pc = ELR_EL1.get();
180180

181181
/* data abort from lower or current level */
182-
if (ec == 0b100100) || (ec == 0b100101) {
182+
if (ec == 0b10_0100) || (ec == 0b10_0101) {
183183
/* check if value in far_el1 is valid */
184184
if (iss & (1 << 10)) == 0 {
185185
/* read far_el1 register, which holds the faulting virtual address */

src/arch/aarch64/kernel/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::arch::aarch64::kernel::core_local::*;
2323
use crate::arch::aarch64::kernel::serial::SerialPort;
2424
use crate::env;
2525

26-
const SERIAL_PORT_BAUDRATE: u32 = 115200;
26+
const SERIAL_PORT_BAUDRATE: u32 = 115_200;
2727

2828
static COM1: SpinMutex<SerialPort> = SpinMutex::new(SerialPort::new(0x800));
2929

src/arch/aarch64/kernel/pci.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@ pub(crate) struct PciConfigRegion(VirtAddr);
2424

2525
impl PciConfigRegion {
2626
pub const fn new(addr: VirtAddr) -> Self {
27-
assert!(addr.as_u64() & 0xFFFFFFF == 0, "Unaligned PCI Config Space");
27+
assert!(
28+
addr.as_u64() & 0x0fff_ffff == 0,
29+
"Unaligned PCI Config Space"
30+
);
2831
Self(addr)
2932
}
3033

3134
#[inline]
3235
fn addr_from_offset(&self, pci_addr: PciAddress, offset: u16) -> usize {
33-
assert!(offset & 0xF000 == 0, "Invalid offset");
36+
assert!(offset & 0xf000 == 0, "Invalid offset");
3437
(u64::from(pci_addr.bus()) << 20
3538
| u64::from(pci_addr.device()) << 15
3639
| u64::from(pci_addr.function()) << 12
37-
| (u64::from(offset) & 0xFFF)
40+
| (u64::from(offset) & 0xfff)
3841
| self.0.as_u64()) as usize
3942
}
4043
}
@@ -246,7 +249,7 @@ pub fn init() {
246249
let size = u64::from_be_bytes(slice.try_into().unwrap());
247250

248251
let pci_address =
249-
virtualmem::allocate_aligned(size.try_into().unwrap(), 0x10000000).unwrap();
252+
virtualmem::allocate_aligned(size.try_into().unwrap(), 0x1000_0000).unwrap();
250253
info!("Mapping PCI Enhanced Configuration Space interface to virtual address {:p} (size {:#X})", pci_address, size);
251254

252255
let mut flags = PageTableEntryFlags::empty();
@@ -268,8 +271,8 @@ pub fn init() {
268271
assert!(mem64_start > 0);
269272

270273
let max_bus_number = size
271-
/ (PCI_MAX_DEVICE_NUMBER as u64
272-
* PCI_MAX_FUNCTION_NUMBER as u64
274+
/ (u64::from(PCI_MAX_DEVICE_NUMBER)
275+
* u64::from(PCI_MAX_FUNCTION_NUMBER)
273276
* BasePageSize::SIZE);
274277
info!("Scanning PCI Busses 0 to {}", max_bus_number - 1);
275278

@@ -299,12 +302,12 @@ pub fn init() {
299302
cmd |= CommandRegister::IO_ENABLE
300303
| CommandRegister::BUS_MASTER_ENABLE;
301304
}
302-
// Currently, we ignore 32 bit memory bars
303-
/*Bar::Memory32 { address, size, prefetchable } => {
304-
dev.set_bar(i.try_into().unwrap(), Bar::Memory32 { address: mem32_start.try_into().unwrap(), size, prefetchable });
305-
mem32_start += u64::from(size);
306-
cmd |= CommandRegister::MEMORY_ENABLE | CommandRegister::BUS_MASTER_ENABLE;
307-
}*/
305+
Bar::Memory32 { .. } => {
306+
// Currently, we ignore 32 bit memory bars
307+
// dev.set_bar(i.try_into().unwrap(), Bar::Memory32 { address: mem32_start.try_into().unwrap(), size, prefetchable });
308+
// mem32_start += u64::from(size);
309+
// cmd |= CommandRegister::MEMORY_ENABLE | CommandRegister::BUS_MASTER_ENABLE;
310+
}
308311
Bar::Memory64 {
309312
address: _,
310313
size,
@@ -322,7 +325,6 @@ pub fn init() {
322325
cmd |= CommandRegister::MEMORY_ENABLE
323326
| CommandRegister::BUS_MASTER_ENABLE;
324327
}
325-
_ => {}
326328
}
327329
}
328330
}

src/arch/aarch64/kernel/processor.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ impl fmt::Display for CpuFrequencySources {
2727
match &self {
2828
CpuFrequencySources::CommandLine => write!(f, "Command Line"),
2929
CpuFrequencySources::Register => write!(f, "CNTFRQ_EL0"),
30-
_ => panic!("Attempted to print an invalid CPU Frequency Source"),
30+
CpuFrequencySources::Invalid => {
31+
panic!("Attempted to print an invalid CPU Frequency Source")
32+
}
3133
}
3234
}
3335
}
@@ -63,11 +65,14 @@ impl CpuFrequency {
6365

6466
unsafe fn detect_from_cmdline(&mut self) -> Result<(), ()> {
6567
let mhz = env::freq().ok_or(())?;
66-
self.set_detected_cpu_frequency(u32::from(mhz) * 1000000, CpuFrequencySources::CommandLine)
68+
self.set_detected_cpu_frequency(
69+
u32::from(mhz) * 1_000_000,
70+
CpuFrequencySources::CommandLine,
71+
)
6772
}
6873

6974
unsafe fn detect_from_register(&mut self) -> Result<(), ()> {
70-
let hz = CNTFRQ_EL0.get() & 0xFFFFFFFF;
75+
let hz = CNTFRQ_EL0.get() & 0xffff_ffff;
7176
self.set_detected_cpu_frequency(hz.try_into().unwrap(), CpuFrequencySources::Register)
7277
}
7378

@@ -115,7 +120,7 @@ pub fn shutdown(error_code: i32) -> ! {
115120
semihosting::process::exit(error_code)
116121
} else {
117122
unsafe {
118-
const PSCI_SYSTEM_OFF: u64 = 0x84000008;
123+
const PSCI_SYSTEM_OFF: u64 = 0x8400_0008;
119124
// call hypervisor to shut down the system
120125
asm!("hvc #0", in("x0") PSCI_SYSTEM_OFF, options(nomem, nostack));
121126

@@ -132,13 +137,13 @@ pub fn shutdown(error_code: i32) -> ! {
132137
pub fn get_timer_ticks() -> u64 {
133138
// We simulate a timer with a 1 microsecond resolution by taking the CPU timestamp
134139
// and dividing it by the CPU frequency in MHz.
135-
let ticks = 1000000 * u128::from(get_timestamp()) / u128::from(CPU_FREQUENCY.get());
140+
let ticks = 1_000_000 * u128::from(get_timestamp()) / u128::from(CPU_FREQUENCY.get());
136141
u64::try_from(ticks).unwrap()
137142
}
138143

139144
#[inline]
140145
pub fn get_frequency() -> u16 {
141-
(CPU_FREQUENCY.get() / 1000000).try_into().unwrap()
146+
(CPU_FREQUENCY.get() / 1_000_000).try_into().unwrap()
142147
}
143148

144149
#[inline]
@@ -219,7 +224,7 @@ pub fn detect_frequency() {
219224
fn __set_oneshot_timer(wakeup_time: Option<u64>) {
220225
if let Some(wt) = wakeup_time {
221226
// wt is the absolute wakeup time in microseconds based on processor::get_timer_ticks.
222-
let deadline = u128::from(wt) * u128::from(CPU_FREQUENCY.get()) / 1000000;
227+
let deadline = u128::from(wt) * u128::from(CPU_FREQUENCY.get()) / 1_000_000;
223228
let deadline = u64::try_from(deadline).unwrap();
224229

225230
unsafe {

src/arch/aarch64/kernel/scheduler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ impl TaskFrame for Task {
354354
// Set a marker for debugging at the very top.
355355
let mut stack = self.stacks.get_kernel_stack() + self.stacks.get_kernel_stack_size()
356356
- TaskStacks::MARKER_SIZE;
357-
*stack.as_mut_ptr::<u64>() = 0xDEAD_BEEFu64;
357+
*stack.as_mut_ptr::<u64>() = 0xdead_beefu64;
358358

359359
// Put the State structure expected by the ASM switch() function on the stack.
360360
stack -= mem::size_of::<State>();
@@ -374,7 +374,7 @@ impl TaskFrame for Task {
374374
(*state).spsel = 1;
375375

376376
/* Zero the condition flags. */
377-
(*state).spsr_el1 = 0x3E5;
377+
(*state).spsr_el1 = 0x3e5;
378378

379379
// Set the task's stack pointer entry to the stack we have just crafted.
380380
self.last_stack_pointer = stack;
@@ -383,7 +383,7 @@ impl TaskFrame for Task {
383383
self.user_stack_pointer = self.stacks.get_user_stack()
384384
+ self.stacks.get_user_stack_size()
385385
- TaskStacks::MARKER_SIZE;
386-
*self.user_stack_pointer.as_mut_ptr::<u64>() = 0xDEAD_BEEFu64;
386+
*self.user_stack_pointer.as_mut_ptr::<u64>() = 0xdead_beefu64;
387387
(*state).sp_el0 = self.user_stack_pointer.as_u64();
388388
}
389389
}

src/arch/aarch64/kernel/start.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ unsafe extern "C" fn pre_init(boot_info: Option<&'static RawBootInfo>, cpu_id: u
7575
{
7676
error!("SMP support deactivated");
7777
loop {
78-
crate::arch::processor::halt()
78+
crate::arch::processor::halt();
7979
}
8080
}
8181
#[cfg(feature = "smp")]

src/arch/aarch64/kernel/switch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ macro_rules! kernel_function_impl {
1212
$(
1313
assert!(mem::size_of::<$A>() <= mem::size_of::<usize>());
1414
let $arg = {
15-
let mut reg = 0_usize;
15+
let mut reg = 0usize;
1616
// SAFETY: $A is smaller than usize and directly fits in a register
1717
// Since f takes $A as argument via C calling convention, any upper bytes do not matter.
18-
ptr::write(ptr::from_mut(&mut reg) as _, $arg);
18+
ptr::write(ptr::from_mut(&mut reg).cast(), $arg);
1919
reg
2020
};
2121
)*

src/arch/aarch64/kernel/systemtime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub fn init() {
8484
);
8585

8686
let boot_time =
87-
OffsetDateTime::from_unix_timestamp(rtc_read(RTC_DR) as i64).unwrap();
87+
OffsetDateTime::from_unix_timestamp(rtc_read(RTC_DR).into()).unwrap();
8888
info!("Hermit booted on {boot_time}");
8989

9090
let micros = u64::try_from(boot_time.unix_timestamp_nanos() / 1000).unwrap();

0 commit comments

Comments
 (0)