diff --git a/build.rs b/build.rs index f0906d844d..96c3ea5c78 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unwrap_used)] // the build script can panic + use std::{env, path::Path, process::Command}; use toml::Table; @@ -94,5 +96,5 @@ fn main() { _ => (), } - let _ = parse_kconfig(&*arch_str); + let _ = parse_kconfig(&arch_str); } diff --git a/rmm/src/allocator/frame/buddy.rs b/rmm/src/allocator/frame/buddy.rs index d29d196f9b..bd00c44f3a 100644 --- a/rmm/src/allocator/frame/buddy.rs +++ b/rmm/src/allocator/frame/buddy.rs @@ -20,13 +20,7 @@ struct BuddyEntry { impl Clone for BuddyEntry { fn clone(&self) -> Self { - Self { - base: self.base, - size: self.size, - skip: self.skip, - used: self.used, - phantom: PhantomData, - } + *self } } impl Copy for BuddyEntry {} @@ -69,6 +63,7 @@ impl BuddyEntry { } } + #[expect(clippy::unit_arg)] unsafe fn set_usage(&self, page: usize, usage: BuddyUsage) -> Option<()> { unsafe { let addr = self.usage_addr(page)?; @@ -104,7 +99,7 @@ impl BuddyAllocator { // by the bump allocator let mut offset = bump_allocator.offset(); for old_area in bump_allocator.areas().iter() { - let mut area = old_area.clone(); + let mut area = *old_area; if offset >= area.size { offset -= area.size; continue; diff --git a/rmm/src/arch/x86_shared.rs b/rmm/src/arch/x86_shared.rs index de42790689..a55a9fd9e3 100644 --- a/rmm/src/arch/x86_shared.rs +++ b/rmm/src/arch/x86_shared.rs @@ -1,3 +1,5 @@ +#![expect(clippy::identity_op)] + // Page attribute table is indexed by PAT(7) PCD(4) PWT(3) pub(crate) const _PAT_WB: usize = (0b0 << 7) + (0b00 << 3); pub(crate) const _PAT_WT: usize = (0b0 << 7) + (0b01 << 3); diff --git a/rmm/src/lib.rs b/rmm/src/lib.rs index 5fb35a57be..3088ec989e 100644 --- a/rmm/src/lib.rs +++ b/rmm/src/lib.rs @@ -1,4 +1,5 @@ #![no_std] +#![allow(clippy::new_without_default)] pub use crate::{allocator::*, arch::*, page::*}; @@ -38,6 +39,7 @@ impl PhysicalAddress { self.0 } + #[expect(clippy::should_implement_trait)] #[inline(always)] pub fn add(self, offset: usize) -> Self { Self(self.0 + offset) @@ -66,6 +68,7 @@ impl VirtualAddress { self.0 } + #[expect(clippy::should_implement_trait)] #[inline(always)] pub fn add(self, offset: usize) -> Self { Self(self.0 + offset) diff --git a/rmm/src/page/flush.rs b/rmm/src/page/flush.rs index 0a128fae43..0638fce807 100644 --- a/rmm/src/page/flush.rs +++ b/rmm/src/page/flush.rs @@ -24,6 +24,7 @@ impl PageFlush { A::invalidate(self.virt); } + #[expect(clippy::forget_non_drop)] pub unsafe fn ignore(self) { mem::forget(self); } diff --git a/rmm/src/page/mapper.rs b/rmm/src/page/mapper.rs index 5a0bd440c8..25d794b2d5 100644 --- a/rmm/src/page/mapper.rs +++ b/rmm/src/page/mapper.rs @@ -84,9 +84,7 @@ impl PageMapper { let old_entry = p1.entry(i)?; let old_phys = old_entry.address().ok()?; let old_flags = old_entry.flags(); - let Some((new_phys, new_flags)) = f(old_phys, old_flags) else { - return None; - }; + let (new_phys, new_flags) = f(old_phys, old_flags)?; // TODO: Higher-level PageEntry::new interface? let new_entry = PageEntry::new(new_phys.data(), new_flags.data()); p1.set_entry(i, new_entry); diff --git a/src/acpi/madt/arch/x86.rs b/src/acpi/madt/arch/x86.rs index 3503124f1f..2cf7763131 100644 --- a/src/acpi/madt/arch/x86.rs +++ b/src/acpi/madt/arch/x86.rs @@ -73,7 +73,8 @@ pub(super) fn init(madt: Madt) { allocate_p2frame(4) .expect("no more frames in acpi stack_start") .base(), - ).data(); + ) + .data(); let stack_end = stack_start + (PAGE_SIZE << 4); let pcr_ptr = crate::arch::gdt::allocate_and_init_pcr(cpu_id, stack_end); @@ -97,6 +98,7 @@ pub(super) fn init(madt: Madt) { ap_ready.write(0); ap_args_ptr.write(&args as *const _ as u64); ap_page_table.write(page_table_physaddr as u64); + #[expect(clippy::fn_to_numeric_cast)] ap_code.write(kstart_ap as u64); // TODO: Is this necessary (this fence)? diff --git a/src/acpi/rsdp.rs b/src/acpi/rsdp.rs index 28be137ebb..f10c5ac989 100644 --- a/src/acpi/rsdp.rs +++ b/src/acpi/rsdp.rs @@ -17,12 +17,10 @@ pub struct Rsdp { impl Rsdp { pub unsafe fn get_rsdp(already_supplied_rsdp: Option<*const u8>) -> Option { - if let Some(rsdp_ptr) = already_supplied_rsdp { + already_supplied_rsdp.map(|rsdp_ptr| { // TODO: Validate - Some(unsafe { *(rsdp_ptr as *const Rsdp) }) - } else { - None - } + unsafe { *(rsdp_ptr as *const Rsdp) } + }) } /// Get the RSDT or XSDT address diff --git a/src/arch/x86_64/alternative.rs b/src/arch/x86_64/alternative.rs index 15aa2c90c7..be89183bbd 100644 --- a/src/arch/x86_64/alternative.rs +++ b/src/arch/x86_64/alternative.rs @@ -39,9 +39,16 @@ pub struct AltReloc { pub unsafe fn early_init(bsp: bool) { unsafe { let relocs_offset = crate::kernel_executable_offsets::__altrelocs_start(); + // __altrelocs_end > __altrelocs_start so this cannot overflow + #[expect(clippy::arithmetic_side_effects)] let relocs_size = crate::kernel_executable_offsets::__altrelocs_end() - relocs_offset; - assert_eq!(relocs_size % size_of::(), 0); + // AltReloc is not a ZST so the modulo and division will never panic + #[expect(clippy::arithmetic_side_effects)] + { + assert_eq!(relocs_size % size_of::(), 0) + } + #[expect(clippy::arithmetic_side_effects)] let relocs = core::slice::from_raw_parts( relocs_offset as *const AltReloc, relocs_size / size_of::(), @@ -106,6 +113,8 @@ pub unsafe fn early_init(bsp: bool) { }) .expect("CPUID said AVX was supported but there's no state info"); + // 16 * size_of::() is well below usize::MAX + #[expect(clippy::arithmetic_side_effects)] if state.size() as usize != 16 * core::mem::size_of::() { warn!("Unusual AVX state size {}", state.size()); } @@ -218,6 +227,11 @@ unsafe fn overwrite(relocs: &[AltReloc], enable: KcpuFeatures) { dst.copy_from_slice(altcode); for chunk in dst_nops.chunks_mut(NOPS_TABLE.len()) { + // `chunk.len() - 1` is always in bounds because we are chunking by + // `NOPS_TABLE.len()` + #[expect(clippy::indexing_slicing)] + // `chunk.len()` will never be 0 + #[expect(clippy::arithmetic_side_effects)] chunk.copy_from_slice(NOPS_TABLE[chunk.len() - 1]); } trace!("feature {} new {:x?} altcode {:x?}", name, code, altcode); @@ -228,6 +242,11 @@ unsafe fn overwrite(relocs: &[AltReloc], enable: KcpuFeatures) { // Not strictly necessary, but reduces the number of instructions using longer nop // instructions. for chunk in padded.chunks_mut(NOPS_TABLE.len()) { + // `chunk.len() - 1` is always in bounds because we are chunking by + // `NOPS_TABLE.len()` + #[expect(clippy::indexing_slicing)] + // `chunk.len()` will never be 0 + #[expect(clippy::arithmetic_side_effects)] chunk.copy_from_slice(NOPS_TABLE[chunk.len() - 1]); } @@ -282,6 +301,8 @@ mod xsave { pub fn kfx_size() -> usize { #[cfg(not(cpu_feature_never = "xsave"))] { + // This wont overflow + #[expect(clippy::arithmetic_side_effects)] match xsave::info() { Some(info) => FXSAVE_SIZE + XSAVE_HEADER_SIZE + info.xsave_size as usize, None => FXSAVE_SIZE, diff --git a/src/arch/x86_64/interrupt/handler.rs b/src/arch/x86_64/interrupt/handler.rs index e3a0d71c0c..46b8051a06 100644 --- a/src/arch/x86_64/interrupt/handler.rs +++ b/src/arch/x86_64/interrupt/handler.rs @@ -133,7 +133,7 @@ impl InterruptStack { pub fn trace(&self) { self.dump(); unsafe { - panic::user_stack_trace(&self); + panic::user_stack_trace(self); panic::stack_trace(); } } diff --git a/src/arch/x86_shared/gdt.rs b/src/arch/x86_shared/gdt.rs index 5378977c5d..cad344f3c2 100644 --- a/src/arch/x86_shared/gdt.rs +++ b/src/arch/x86_shared/gdt.rs @@ -282,6 +282,8 @@ fn init_pcr(pcr: &mut ProcessorControlRegion, stack_end: usize) { pcr.gdt[GDT_TSS].set_offset(tss_lo); pcr.gdt[GDT_TSS].set_limit(size_of::() as u32 + IOBITMAP_SIZE); + // GDT is aligned to 8 bytes + #[expect(clippy::cast_ptr_alignment)] unsafe { (&mut pcr.gdt[GDT_TSS_HIGH] as *mut GdtEntry) .cast::() diff --git a/src/context/arch/x86_64.rs b/src/context/arch/x86_64.rs index e9523d4bfc..62fdb4cfe9 100644 --- a/src/context/arch/x86_64.rs +++ b/src/context/arch/x86_64.rs @@ -91,6 +91,12 @@ impl Context { const INT_REGS_SIZE: usize = core::mem::size_of::(); + // Kstack::initial_top() is always at least 8 byte aligned. assertion to be safe + debug_assert!( + (stack_top as usize).is_multiple_of(8), + "Kstack not 8 byte aligned" + ); + #[expect(clippy::cast_ptr_alignment)] unsafe { if userspace_allowed { // Zero-initialize InterruptStack registers. diff --git a/src/context/memory.rs b/src/context/memory.rs index 3994257f5d..9451944844 100644 --- a/src/context/memory.rs +++ b/src/context/memory.rs @@ -2450,6 +2450,8 @@ pub fn try_correcting_page_tables( Ok(()) } +// TODO: maybe refactor the return type into a struct/typedef? +#[expect(clippy::type_complexity)] /// XXX: This require passing L3 addr_space_guard. /// Caller must ensure there's no other lock being held at this point. /// Caller also need to provide clean token for the new AddrSpace. diff --git a/src/context/switch.rs b/src/context/switch.rs index 188d75aa47..4460bcf827 100644 --- a/src/context/switch.rs +++ b/src/context/switch.rs @@ -216,19 +216,19 @@ pub fn switch(token: &mut CleanLockToken) -> SwitchResult { if switch_context_opt.is_none() { let mut this_contexts = contexts_mut(token.token()); let (this_contexts, mut token) = this_contexts.token_split(); - if let Some(mut free_contexts) = free_contexts_try(token.token()) { - if let Some(context) = free_contexts.pop_last() { - // Check if we can run this free context immediately - if let Some(next_context) = context.upgrade() { - let mut next_context_guard = unsafe { next_context.write_arc() }; - if let UpdateResult::CanSwitch = - unsafe { update_runnable(&mut next_context_guard, cpu_id, switch_time) } - { - switch_context_opt = Some(next_context_guard); - } + if let Some(mut free_contexts) = free_contexts_try(token.token()) + && let Some(context) = free_contexts.pop_last() + { + // Check if we can run this free context immediately + if let Some(next_context) = context.upgrade() { + let mut next_context_guard = unsafe { next_context.write_arc() }; + if let UpdateResult::CanSwitch = + unsafe { update_runnable(&mut next_context_guard, cpu_id, switch_time) } + { + switch_context_opt = Some(next_context_guard); } - this_contexts.insert(context); } + this_contexts.insert(context); } } diff --git a/src/devices/uart_16550.rs b/src/devices/uart_16550.rs index a2f3c84f76..9b93e2c835 100644 --- a/src/devices/uart_16550.rs +++ b/src/devices/uart_16550.rs @@ -31,7 +31,7 @@ bitflags! { } #[allow(dead_code)] -#[repr(packed(4))] +#[repr(C, packed(4))] pub struct SerialPort { /// Data register, read to receive, write to send data: T, diff --git a/src/dtb/mod.rs b/src/dtb/mod.rs index e8f4944e99..b9b8b23094 100644 --- a/src/dtb/mod.rs +++ b/src/dtb/mod.rs @@ -218,7 +218,7 @@ pub fn diag_uart_range<'a>(dtb: &'a Fdt) -> Option<(PhysicalAddress, usize, bool .and_then(NodeProperty::as_str)?; let mut reg = uart_node.reg()?; - let memory = reg.nth(0)?; + let memory = reg.next()?; let address = get_mmio_address(dtb, &uart_node, &memory)?; Some(( diff --git a/src/main.rs b/src/main.rs index 3f52f442fe..ba1cb52bec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,8 @@ #![feature(btree_cursors)] #![cfg_attr(not(test), no_std)] #![cfg_attr(not(test), no_main)] +#![allow(clippy::new_without_default)] + #[macro_use] extern crate alloc; diff --git a/src/profiling.rs b/src/profiling.rs index 76e802556f..74f95007d8 100644 --- a/src/profiling.rs +++ b/src/profiling.rs @@ -102,8 +102,7 @@ impl RingBuffer { })) } } -const NULL: AtomicPtr = AtomicPtr::new(core::ptr::null_mut()); -pub static BUFS: [AtomicPtr; 4] = [NULL; 4]; +pub static BUFS: [AtomicPtr; 4] = [const { AtomicPtr::new(core::ptr::null_mut()) }; 4]; pub const PROFILE_TOGGLEABLE: bool = true; pub static IS_PROFILING: AtomicBool = AtomicBool::new(false); @@ -138,10 +137,7 @@ pub fn drain_buffer(cpu_num: LogicalCpuId, buf: UserSliceWo) -> Result { return Ok(0); }; let byte_slices = src.peek().map(|words| { - core::slice::from_raw_parts( - words.as_ptr().cast::(), - words.len() * size_of::(), - ) + core::slice::from_raw_parts(words.as_ptr().cast::(), size_of_val(words)) }); let copied_1 = buf.copy_common_bytes_from_slice(byte_slices[0])?; diff --git a/src/scheme/debug.rs b/src/scheme/debug.rs index 7909a501eb..79101e6570 100644 --- a/src/scheme/debug.rs +++ b/src/scheme/debug.rs @@ -43,14 +43,14 @@ pub struct DebugScheme; #[repr(usize)] enum SpecialFds { - Default = !0, - NoPreserve = !0 - 1, - DisableGraphicalDebug = !0 - 2, + Default = -1isize as usize, + NoPreserve = -2isize as usize, + DisableGraphicalDebug = -3isize as usize, #[cfg(feature = "profiling")] - CtlProfiling = !0 - 3, + CtlProfiling = -4isize as usize, - SchemeRoot = !0 - 4, + SchemeRoot = -5isize as usize, } impl KernelScheme for DebugScheme { diff --git a/src/scheme/dtb.rs b/src/scheme/dtb.rs index 32e0aaf439..824e8b4a9a 100644 --- a/src/scheme/dtb.rs +++ b/src/scheme/dtb.rs @@ -42,7 +42,7 @@ impl DtbScheme { DATA.call_once(|| { data_init = true; - Box::from(DTB_BINARY.get().map(|&d| d).unwrap_or(&[])) + Box::from(DTB_BINARY.get().copied().unwrap_or(&[])) }); if !data_init { @@ -176,7 +176,7 @@ impl KernelScheme for DtbScheme { st_mode: MODE_FILE, st_uid: 0, st_gid: 0, - st_size: data.len().try_into().unwrap_or(u64::max_value()), + st_size: data.len().try_into().unwrap_or(u64::MAX), ..Default::default() } } diff --git a/src/scheme/irq.rs b/src/scheme/irq.rs index a295ba7f85..90b636acec 100644 --- a/src/scheme/irq.rs +++ b/src/scheme/irq.rs @@ -7,7 +7,7 @@ use core::{ sync::atomic::{AtomicUsize, Ordering}, }; -use alloc::{string::String, vec::Vec}; +use alloc::{borrow::ToOwned, string::String, vec::Vec}; use hashbrown::{hash_map::DefaultHashBuilder, HashMap}; use smallvec::SmallVec; @@ -428,10 +428,9 @@ impl crate::scheme::KernelScheme for IrqScheme { if let &Handle::Irq { irq: handle_irq, .. } = handle + && handle_irq > BASE_IRQ_COUNT { - if handle_irq > BASE_IRQ_COUNT { - set_reserved(LogicalCpuId::BSP, irq_to_vector(handle_irq), false); - } + set_reserved(LogicalCpuId::BSP, irq_to_vector(handle_irq), false); } Ok(()) } @@ -527,10 +526,10 @@ impl crate::scheme::KernelScheme for IrqScheme { let scheme_path = match handle { Handle::Irq { irq, .. } => format!("irq:{}", irq), - Handle::Bsp => format!("irq:bsp"), + Handle::Bsp => "irq:bsp".to_owned(), Handle::Avail(cpu_id) => format!("irq:cpu-{:2x}", cpu_id.get()), Handle::Phandle(phandle, _) => format!("irq:phandle-{}", phandle), - Handle::TopLevel => format!("irq:"), + Handle::TopLevel => "irq:".to_owned(), _ => return Err(Error::new(EBADF)), } .into_bytes(); diff --git a/src/scheme/mod.rs b/src/scheme/mod.rs index 6de078695a..87ffdc2649 100644 --- a/src/scheme/mod.rs +++ b/src/scheme/mod.rs @@ -226,13 +226,10 @@ impl SchemeList { let scheme = handles().write(token.token()).remove(&SchemeId(id)); assert!(scheme.is_some()); - match scheme { - Some(Handle::Scheme(KernelSchemes::User(user))) => { - if let Some(user) = Arc::into_inner(user.inner) { - user.into_drop(token); - } - } - _ => {} + if let Some(Handle::Scheme(KernelSchemes::User(user))) = scheme + && let Some(user) = Arc::into_inner(user.inner) + { + user.into_drop(token); } } } diff --git a/src/scheme/pipe.rs b/src/scheme/pipe.rs index fbaa17af6a..418a5cd8a3 100644 --- a/src/scheme/pipe.rs +++ b/src/scheme/pipe.rs @@ -136,18 +136,16 @@ impl KernelScheme for PipeScheme { }; if can_remove { - match { PIPES.write(token.token()).remove(&key) } { - Some(Handle::Pipe(pipe)) => { - if let Some(pipe) = Arc::into_inner(pipe) { - { - pipe.read_condition.into_drop(token); - } - { - pipe.write_condition.into_drop(token); - } - } + let handle = PIPES.write(token.token()).remove(&key); + if let Some(Handle::Pipe(pipe)) = handle + && let Some(pipe) = Arc::into_inner(pipe) + { + { + pipe.read_condition.into_drop(token); + } + { + pipe.write_condition.into_drop(token); } - _ => {} } } diff --git a/src/scheme/proc.rs b/src/scheme/proc.rs index 39c8116edd..410a8da517 100644 --- a/src/scheme/proc.rs +++ b/src/scheme/proc.rs @@ -85,8 +85,8 @@ fn try_stop_context( "process can't have been restarted, we stopped it!" ); - let (mut context, token) = context.token_split(); - let ret = callback(&mut context, token); + let (context, token) = context.token_split(); + let ret = callback(context, token); context.status = prev_status; @@ -514,7 +514,7 @@ impl KernelScheme for ProcScheme { let requested_dst_base = (map.address != 0 || fixed).then_some(requested_dst_page); let mut src_addr_space_guard = addrspace.acquire_write(token.downgrade()); - let (mut src_addr_space, lock_token) = src_addr_space_guard.token_split(); + let (src_addr_space, lock_token) = src_addr_space_guard.token_split(); let src_page_count = NonZeroUsize::new(src_span.count).ok_or(Error::new(EINVAL))?; @@ -544,7 +544,7 @@ impl KernelScheme for ProcScheme { |dst_page, _, dst_mapper, flusher| { Grant::borrow( Arc::clone(addrspace), - &mut src_addr_space, + src_addr_space, src_span.base, dst_page, src_span.count, @@ -1408,7 +1408,7 @@ impl ContextHandle { Ok(grants_read * mem::size_of::()) } - ContextHandle::Filetable { data, .. } => read_from(buf, &data, offset), + ContextHandle::Filetable { data, .. } => read_from(buf, data, offset), ContextHandle::MmapMinAddr(addrspace) => { let mut token = token.token(); let addr = addrspace.acquire_read(token.downgrade()); diff --git a/src/scheme/sys/context.rs b/src/scheme/sys/context.rs index d51eccca24..644b847c29 100644 --- a/src/scheme/sys/context.rs +++ b/src/scheme/sys/context.rs @@ -1,4 +1,5 @@ use alloc::{ + borrow::ToOwned, string::{String, ToString}, vec::Vec, }; @@ -55,11 +56,9 @@ pub fn resource(token: &mut CleanLockToken) -> Result> { let cpu_string = match context.cpu_id { Some(cpu_id) => { - format!("{}", cpu_id) - } - _ => { - format!("?") + format!("{cpu_id}") } + _ => "?".to_owned(), }; let affinity = context.sched_affinity.to_string(); diff --git a/src/scheme/sys/stat.rs b/src/scheme/sys/stat.rs index 2176023d1b..69f37b3b82 100644 --- a/src/scheme/sys/stat.rs +++ b/src/scheme/sys/stat.rs @@ -47,7 +47,7 @@ fn get_cpu_stats() -> String { total_kernel += stat.kernel; total_idle += stat.idle; total_irq += stat.irq; - let _ = write!(&mut cpu_data, "cpu{} {}\n", id.get(), stat); + let _ = writeln!(&mut cpu_data, "cpu{} {}", id.get(), stat); } format!( "cpu {total_user} {total_nice} {total_kernel} {total_idle} {total_irq}\n\ diff --git a/src/scheme/time.rs b/src/scheme/time.rs index e7bb1396e9..13d3dac25a 100644 --- a/src/scheme/time.rs +++ b/src/scheme/time.rs @@ -166,7 +166,7 @@ impl KernelScheme for TimeScheme { let mut bytes_read = 0; for current_chunk in buf.in_exact_chunks(mem::size_of::()) { - let arch_time = match (handle.clock.clone(), handle.kind.clone()) { + let arch_time = match (handle.clock, handle.kind.clone()) { (CLOCK_REALTIME, TimeSchemeKind::Default | TimeSchemeKind::ClockGettime) => { time::realtime(token) } @@ -211,7 +211,7 @@ impl KernelScheme for TimeScheme { for current_chunk in buf.in_exact_chunks(mem::size_of::()) { let time = unsafe { current_chunk.read_exact::()? }; - match (handle.clock.clone(), handle.kind.clone()) { + match (handle.clock, handle.kind.clone()) { (_, TimeSchemeKind::Default | TimeSchemeKind::Timer) => { timeout::register( GlobalSchemes::Time.scheme_id(), diff --git a/src/scheme/user.rs b/src/scheme/user.rs index 0cfdd1572c..3d8a8d5db8 100644 --- a/src/scheme/user.rs +++ b/src/scheme/user.rs @@ -68,7 +68,7 @@ enum Response { } impl Response { - fn as_regular(self) -> Result { + fn into_regular(self) -> Result { match self { Response::Regular(res, _, _) => res, Response::Fd(_) | Response::MultipleFds(_) => Err(Error::new(EIO)), @@ -1082,7 +1082,7 @@ impl UserInner { //let mapping_is_lazy = map.flags.contains(MapFlags::MAP_LAZY); let mapping_is_lazy = false; - let base_page_opt = (!mapping_is_lazy).then_some(response.as_regular()?); + let base_page_opt = (!mapping_is_lazy).then_some(response.into_regular()?); let file_ref = GrantFileRef { description: desc, @@ -1443,7 +1443,7 @@ impl KernelScheme for UserScheme { ) { Ok(res) => { address.release(token)?; - res.as_regular() + res.into_regular() } Err(e) => { let _ = address.release(token); @@ -1464,7 +1464,7 @@ impl KernelScheme for UserScheme { &mut PageSpan::empty(), token, )? - .as_regular() + .into_regular() .map(|o| o as u64) } @@ -1479,7 +1479,7 @@ impl KernelScheme for UserScheme { &mut PageSpan::empty(), token, )? - .as_regular()?; + .into_regular()?; Ok(()) } @@ -1502,7 +1502,7 @@ impl KernelScheme for UserScheme { &mut PageSpan::empty(), token, )? - .as_regular()?; + .into_regular()?; Ok(()) } @@ -1523,7 +1523,7 @@ impl KernelScheme for UserScheme { &mut PageSpan::empty(), token, )? - .as_regular() + .into_regular() } fn fevent( @@ -1542,7 +1542,7 @@ impl KernelScheme for UserScheme { &mut PageSpan::empty(), token, )? - .as_regular() + .into_regular() .map(EventFlags::from_bits_truncate) } @@ -1564,7 +1564,7 @@ impl KernelScheme for UserScheme { ) { Ok(res) => { address.release(token)?; - res.as_regular() + res.into_regular() } Err(err) => { let _ = address.release(token); @@ -1592,7 +1592,7 @@ impl KernelScheme for UserScheme { ) { Ok(res) => { address.release(token)?; - res.as_regular() + res.into_regular() } Err(err) => { let _ = address.release(token); @@ -1613,7 +1613,7 @@ impl KernelScheme for UserScheme { &mut PageSpan::empty(), token, )? - .as_regular()?; + .into_regular()?; Ok(()) } @@ -1628,7 +1628,7 @@ impl KernelScheme for UserScheme { &mut PageSpan::empty(), token, )? - .as_regular()?; + .into_regular()?; Ok(()) } @@ -1722,7 +1722,7 @@ impl KernelScheme for UserScheme { address.span(), token, )? - .as_regular(); + .into_regular(); address.release(token)?; result } @@ -1755,7 +1755,7 @@ impl KernelScheme for UserScheme { address.span(), token, )? - .as_regular(); + .into_regular(); address.release(token)?; result @@ -1789,7 +1789,7 @@ impl KernelScheme for UserScheme { address.span(), token, )? - .as_regular(); + .into_regular(); address.release(token)?; result @@ -1812,7 +1812,7 @@ impl KernelScheme for UserScheme { address.span(), token, )? - .as_regular(); + .into_regular(); address.release(token)?; result } @@ -1846,7 +1846,7 @@ impl KernelScheme for UserScheme { address.span(), token, )? - .as_regular(); + .into_regular(); address.release(token)?; result } @@ -1863,7 +1863,7 @@ impl KernelScheme for UserScheme { address.span(), token, )? - .as_regular(); + .into_regular(); address.release(token)?; result.map(|_| ()) } @@ -1880,7 +1880,7 @@ impl KernelScheme for UserScheme { address.span(), token, )? - .as_regular(); + .into_regular(); address.release(token)?; result.map(|_| ()) } @@ -1915,7 +1915,7 @@ impl KernelScheme for UserScheme { token, )?; - res.as_regular()?; + res.into_regular()?; Ok(()) } fn kcall( @@ -1954,7 +1954,7 @@ impl KernelScheme for UserScheme { match inner.call_inner(Vec::new(), sqe, address.span(), token) { Ok(res) => { address.release(token)?; - res.as_regular() + res.into_regular() } Err(e) => { let _ = address.release(token); @@ -2039,7 +2039,7 @@ impl KernelScheme for UserScheme { &mut PageSpan::empty(), token, )? - .as_regular() + .into_regular() } fn kfdread( &self, diff --git a/src/sync/ordered.rs b/src/sync/ordered.rs index a002456ec7..a8cf6fa398 100644 --- a/src/sync/ordered.rs +++ b/src/sync/ordered.rs @@ -474,10 +474,7 @@ impl RwLock { &'a self, lock_token: LockToken<'a, LP>, ) -> Option> { - let inner = match self.inner.try_read() { - Some(inner) => inner, - None => return None, - }; + let inner = self.inner.try_read()?; Some(RwLockReadGuard { inner, lock_token: LockToken::downgraded(lock_token), @@ -488,10 +485,7 @@ impl RwLock { &'a self, lock_token: LockToken<'a, LP>, ) -> Option> { - let inner = match self.inner.try_write() { - Some(inner) => inner, - None => return None, - }; + let inner = self.inner.try_write()?; Some(RwLockWriteGuard { inner, lock_token: LockToken::downgraded(lock_token), @@ -526,10 +520,7 @@ impl RwLock { } } }; - RwLockWriteGuard { - inner, - lock_token: lock_token, - } + RwLockWriteGuard { inner, lock_token } } /// Arcquires the lock_token to replace older LockUpgradableGuard. @@ -559,10 +550,7 @@ impl RwLock { } } }; - RwLockUpgradableGuard { - inner, - lock_token: lock_token, - } + RwLockUpgradableGuard { inner, lock_token } } // Unsafe due to not using token, currently required by context::switch diff --git a/src/syscall/debug.rs b/src/syscall/debug.rs index a81c52fbd8..112fbabf6e 100644 --- a/src/syscall/debug.rs +++ b/src/syscall/debug.rs @@ -1,4 +1,4 @@ -use alloc::{string::String, vec::Vec}; +use alloc::{borrow::ToOwned, string::String, vec::Vec}; use core::{ascii, fmt::Debug, mem}; use super::{ @@ -187,7 +187,7 @@ pub fn format_call(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, g c, d ), - SYS_YIELD => format!("yield()"), + SYS_YIELD => "yield()".to_owned(), _ => format!( "UNKNOWN{} {:#X}({:#X}, {:#X}, {:#X}, {:#X}, {:#X}, {:#X})", a, a, b, c, d, e, f, g diff --git a/src/syscall/fs.rs b/src/syscall/fs.rs index 1fc30736c1..37ae57645d 100644 --- a/src/syscall/fs.rs +++ b/src/syscall/fs.rs @@ -120,7 +120,7 @@ pub fn openat( .add_file( FileDescriptor { description: new_description, - cloexec: flags as usize & O_CLOEXEC == O_CLOEXEC, + cloexec: flags & O_CLOEXEC == O_CLOEXEC, }, &mut token, )