Resolve a huge portion of the clippy lints

This commit is contained in:
Speedy_Lex
2025-10-06 12:30:23 +00:00
committed by Jeremy Soller
parent db8fb14614
commit 0931a7f49f
57 changed files with 451 additions and 509 deletions
+3 -3
View File
@@ -103,7 +103,7 @@ impl Context {
// Zero-initialize InterruptStack registers.
stack_top = stack_top.sub(INT_REGS_SIZE);
stack_top.write_bytes(0_u8, INT_REGS_SIZE);
(&mut *stack_top.cast::<InterruptStack>()).init();
(*stack_top.cast::<InterruptStack>()).init();
stack_top = stack_top.sub(core::mem::size_of::<usize>());
stack_top
@@ -199,10 +199,10 @@ impl super::Context {
&& RmmA::virt_is_valid(VirtualAddress::new(regs.gsbase as usize))
{
unsafe {
x86::msr::wrmsr(x86::msr::IA32_FS_BASE, regs.fsbase as u64);
x86::msr::wrmsr(x86::msr::IA32_FS_BASE, regs.fsbase);
// We have to write to KERNEL_GSBASE, because when the kernel returns to
// userspace, it will have executed SWAPGS first.
x86::msr::wrmsr(x86::msr::IA32_KERNEL_GSBASE, regs.gsbase as u64);
x86::msr::wrmsr(x86::msr::IA32_KERNEL_GSBASE, regs.gsbase);
}
self.arch.fsbase = regs.fsbase as usize;
self.arch.gsbase = regs.gsbase as usize;
+12 -17
View File
@@ -329,7 +329,7 @@ impl Context {
&mut self,
addr_space: Option<Arc<AddrSpaceWrapper>>,
) -> Option<Arc<AddrSpaceWrapper>> {
if let (&Some(ref old), &Some(ref new)) = (&self.addr_space, &addr_space)
if let (Some(old), Some(new)) = (&self.addr_space, &addr_space)
&& Arc::ptr_eq(old, new)
{
return addr_space;
@@ -341,7 +341,7 @@ impl Context {
if let Some(ref prev_addrsp) = self.addr_space {
assert!(Arc::ptr_eq(
&this_percpu.current_addrsp.borrow().as_ref().unwrap(),
this_percpu.current_addrsp.borrow().as_ref().unwrap(),
prev_addrsp
));
prev_addrsp
@@ -383,18 +383,14 @@ impl Context {
if !self.can_access_regs() {
return None;
}
let Some(ref kstack) = self.kstack else {
return None;
};
let kstack = self.kstack.as_ref()?;
Some(unsafe { &*kstack.initial_top().sub(size_of::<InterruptStack>()).cast() })
}
pub fn regs_mut(&mut self) -> Option<&mut InterruptStack> {
if !self.can_access_regs() {
return None;
}
let Some(ref mut kstack) = self.kstack else {
return None;
};
let kstack = self.kstack.as_ref()?;
Some(unsafe { &mut *kstack.initial_top().sub(size_of::<InterruptStack>()).cast() })
}
pub fn sigcontrol(&mut self) -> Option<(&Sigcontrol, &SigProcControl, &mut SignalState)> {
@@ -514,14 +510,13 @@ impl Drop for BorrowedHtBuf {
};
//TODO: do not allow drop so lock token can be passed in
let mut token = unsafe { CleanLockToken::new() };
match context.write(token.token()) {
mut context => {
*(if self.head_and_not_tail {
&mut context.syscall_head
} else {
&mut context.syscall_tail
}) = SyscallFrame::Free(inner);
}
let mut context = context.write(token.token());
{
*(if self.head_and_not_tail {
&mut context.syscall_head
} else {
&mut context.syscall_tail
}) = SyscallFrame::Free(inner);
}
}
}
@@ -811,7 +806,7 @@ impl FdTbl {
let desc = context_fd.description.read();
desc.scheme == scheme_id && desc.number == scheme_number
})
.map(|fd| fd.clone())
.cloned()
.ok_or(Error::new(EBADF))
}
+12 -11
View File
@@ -61,8 +61,9 @@ impl UnmapResult {
return Ok(());
};
let (scheme_id, number) = match description.write() {
ref desc => (desc.scheme, desc.number),
let (scheme_id, number) = {
let desc = description.write();
(desc.scheme, desc.number)
};
let scheme_opt = scheme::schemes(token.token()).get(scheme_id).cloned();
@@ -177,7 +178,7 @@ impl AddrSpaceWrapper {
} => continue,
Provider::PhysBorrowed { base } => Grant::physmap(
base.clone(),
base,
PageSpan::new(grant_base, grant_info.page_count),
grant_info.flags,
&mut new.inner.get_mut().table.utable,
@@ -221,7 +222,7 @@ impl AddrSpaceWrapper {
src_base,
..
} => Grant::borrow_grant(
Arc::clone(&address_space),
Arc::clone(address_space),
src_base,
grant_base,
grant_info,
@@ -1995,9 +1996,7 @@ impl Grant {
Provider::AllocatedShared { .. } => Provider::AllocatedShared {
is_pinned_userscheme_borrow: false,
},
Provider::PhysBorrowed { base } => {
Provider::PhysBorrowed { base: base.clone() }
}
Provider::PhysBorrowed { base } => Provider::PhysBorrowed { base },
Provider::FmapBorrowed { ref file_ref, .. } => Provider::FmapBorrowed {
file_ref: file_ref.clone(),
pin_refcount: 0,
@@ -2097,7 +2096,7 @@ impl GrantInfo {
)
}
pub fn can_extract(&self, unpin: bool) -> bool {
!(self.is_pinned() && !unpin)
(!self.is_pinned() || unpin)
| matches!(
self.provider,
Provider::Allocated {
@@ -2617,8 +2616,9 @@ fn correct_inner<'l>(
drop(flusher);
drop(addr_space_guard);
let (scheme_id, scheme_number) = match file_ref.description.read() {
ref desc => (desc.scheme, desc.number),
let (scheme_id, scheme_number) = {
let desc = &file_ref.description.read();
(desc.scheme, desc.number)
};
let user_inner = scheme::schemes(token.token())
.get(scheme_id)
@@ -2742,7 +2742,7 @@ fn handle_free_action(base: Frame, phys_contiguous_count: Option<NonZeroUsize>)
let Some(info) = get_page_info(base) else {
return;
};
if info.remove_ref() == None {
if info.remove_ref().is_none() {
unsafe {
deallocate_frame(base);
}
@@ -2800,6 +2800,7 @@ impl<'guard, 'addrsp> Flusher<'guard, 'addrsp> {
pub fn flush(&mut self) {
let pages = core::mem::take(&mut self.state.pagequeue);
#[expect(clippy::bool_comparison)]
if pages.is_empty() && core::mem::replace(&mut self.state.dirty, false) == false {
return;
}
+3 -5
View File
@@ -73,14 +73,12 @@ pub use self::arch::empty_cr3;
static CONTEXTS: RwLock<L1, BTreeSet<ContextRef>> = RwLock::new(BTreeSet::new());
/// Get the global schemes list, const
pub fn contexts<'a>(token: LockToken<'a, L0>) -> RwLockReadGuard<'a, L1, BTreeSet<ContextRef>> {
pub fn contexts(token: LockToken<'_, L0>) -> RwLockReadGuard<'_, L1, BTreeSet<ContextRef>> {
CONTEXTS.read(token)
}
/// Get the global schemes list, mutable
pub fn contexts_mut<'a>(
token: LockToken<'a, L0>,
) -> RwLockWriteGuard<'a, L1, BTreeSet<ContextRef>> {
pub fn contexts_mut(token: LockToken<'_, L0>) -> RwLockWriteGuard<'_, L1, BTreeSet<ContextRef>> {
CONTEXTS.write(token)
}
@@ -115,7 +113,7 @@ pub fn init(token: &mut CleanLockToken) {
pub fn current() -> Arc<ContextLock> {
PercpuBlock::current()
.switch_internals
.with_context(|context| Arc::clone(context))
.with_context(Arc::clone)
}
pub fn try_current() -> Option<Arc<ContextLock>> {
PercpuBlock::current()
+4 -5
View File
@@ -1,6 +1,6 @@
///! This module provides a context-switching mechanism that utilizes a simple round-robin scheduler.
///! The scheduler iterates over available contexts, selecting the next context to run, while
///! handling process states and synchronization.
//! This module provides a context-switching mechanism that utilizes a simple round-robin scheduler.
//! The scheduler iterates over available contexts, selecting the next context to run, while
//! handling process states and synchronization.
use core::{
cell::{Cell, RefCell},
hint, mem,
@@ -16,7 +16,6 @@ use crate::{
cpu_set::LogicalCpuId,
cpu_stats,
percpu::PercpuBlock,
ptrace,
sync::CleanLockToken,
time,
};
@@ -208,7 +207,7 @@ pub fn switch(token: &mut CleanLockToken) -> SwitchResult {
// Check if the context is runnable and can be switched to.
if let UpdateResult::CanSwitch =
unsafe { update_runnable(&mut *next_context_guard, cpu_id) }
unsafe { update_runnable(&mut next_context_guard, cpu_id) }
{
// Store locks for previous and next context and break out from loop
// for the switch
+1 -1
View File
@@ -30,7 +30,7 @@ fn init_registry() -> Mutex<L1, Registry> {
}
/// Get the global timeouts list
fn registry<'a>(token: LockToken<'a, L0>) -> MutexGuard<'a, L1, Registry> {
fn registry(token: LockToken<'_, L0>) -> MutexGuard<'_, L1, Registry> {
REGISTRY.call_once(init_registry).lock(token)
}