kernel: services: fix all clippy warnings

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-08-06 10:16:29 +08:00
parent d4675ef9cf
commit 9dc4fcbf55

View file

@ -197,18 +197,12 @@ impl Default for ProcessInner {
impl Process { impl Process {
/// This process has at least one context that may be run /// This process has at least one context that may be run
pub fn runnable(&self) -> bool { pub fn runnable(&self) -> bool {
match self.state { matches!(self.state, ProcessState::Setup(_) | ProcessState::Ready(_))
ProcessState::Setup(_) | ProcessState::Ready(_) => true,
_ => false,
}
} }
/// This process slot is unallocated and may be turn into a process /// This process slot is unallocated and may be turn into a process
pub fn free(&self) -> bool { pub fn free(&self) -> bool {
match self.state { matches!(self.state, ProcessState::Free)
ProcessState::Free => true,
_ => false,
}
} }
pub fn activate(&self) -> Result<(), xous_kernel::Error> { pub fn activate(&self) -> Result<(), xous_kernel::Error> {
@ -261,7 +255,7 @@ static mut SYSTEM_SERVICES: SystemServices = SystemServices {
ppid: unsafe { PID::new_unchecked(1) }, ppid: unsafe { PID::new_unchecked(1) },
pid: unsafe { PID::new_unchecked(1) }, pid: unsafe { PID::new_unchecked(1) },
mapping: arch::mem::DEFAULT_MEMORY_MAPPING, mapping: arch::mem::DEFAULT_MEMORY_MAPPING,
current_thread: 0 as TID, current_thread: 0_usize,
previous_thread: INITIAL_TID as TID, previous_thread: INITIAL_TID as TID,
exception_handler: None, exception_handler: None,
}; MAX_PROCESS_COUNT], }; MAX_PROCESS_COUNT],
@ -335,7 +329,7 @@ impl SystemServices {
// KernelArguments value to a SystemServices Process value. // KernelArguments value to a SystemServices Process value.
for init in init_offsets.iter() { for init in init_offsets.iter() {
let pid = (init.satp >> 22) & ((1 << 9) - 1); let pid = (init.satp >> 22) & ((1 << 9) - 1);
let ref mut process = self.processes[(pid - 1) as usize]; let process = &mut self.processes[(pid - 1) as usize];
// println!( // println!(
// "Process: SATP: {:08x} PID: {} Memory: {:08x} PC: {:08x} SP: {:08x} Index: {}", // "Process: SATP: {:08x} PID: {} Memory: {:08x} PC: {:08x} SP: {:08x} Index: {}",
// init.satp, // init.satp,
@ -616,10 +610,10 @@ impl SystemServices {
_ => false, _ => false,
}) })
} else { } else {
Ok(match process.state { Ok(matches!(
ProcessState::Running(_) | ProcessState::Ready(_) | ProcessState::Sleeping => true, process.state,
_ => false, ProcessState::Running(_) | ProcessState::Ready(_) | ProcessState::Sleeping
}) ))
} }
} }
@ -1715,6 +1709,7 @@ impl SystemServices {
ArchProcess::with_inner_mut(|process_inner| { ArchProcess::with_inner_mut(|process_inner| {
// Look through the connection map for (1) a free slot, and (2) an // Look through the connection map for (1) a free slot, and (2) an
// existing connection // existing connection
#[allow(clippy::manual_flatten)]
for server_idx_opt in process_inner.connection_map.iter_mut() { for server_idx_opt in process_inner.connection_map.iter_mut() {
if let Some(client_server_idx) = server_idx_opt { if let Some(client_server_idx) = server_idx_opt {
if client_server_idx.get() == (server_idx + 2) as _ { if client_server_idx.get() == (server_idx + 2) as _ {
@ -2016,11 +2011,9 @@ impl SystemServices {
// Look through the connection map for a connection // Look through the connection map for a connection
// that matches this index. Note that connection map entries // that matches this index. Note that connection map entries
// are offset by two, because 0 == free and 1 == "tombstone". // are offset by two, because 0 == free and 1 == "tombstone".
for mapping in process_inner.connection_map.iter_mut() { for mapping in process_inner.connection_map.iter_mut().flatten() {
if let Some(mapping) = mapping { if mapping.get() == (idx as u8) + 2 {
if mapping.get() == (idx as u8) + 2 { *mapping = NonZeroU8::new(1).unwrap();
*mapping = NonZeroU8::new(1).unwrap();
}
} }
} }
}) })
@ -2036,6 +2029,7 @@ impl SystemServices {
} }
// Now that the server has been "Disconnected", free the server entry. // Now that the server has been "Disconnected", free the server entry.
#[allow(clippy::manual_flatten)]
for server in self.servers.iter_mut() { for server in self.servers.iter_mut() {
if let Some(server_inner) = server { if let Some(server_inner) = server {
if server_inner.pid == target_pid { if server_inner.pid == target_pid {
@ -2196,7 +2190,7 @@ impl SystemServices {
let mut offset = 0; let mut offset = 0;
while offset <= arg.size { while offset <= arg.size {
let check_pid = u32::from_le_bytes([ let check_pid = u32::from_le_bytes([
data[offset + 0], data[offset],
data[offset + 1], data[offset + 1],
data[offset + 2], data[offset + 2],
data[offset + 3], data[offset + 3],