Clippy fixes

This commit is contained in:
Jeremy Soller
2022-11-11 13:19:14 -07:00
parent 515a03b870
commit 8e0f54cb31
27 changed files with 76 additions and 87 deletions
+15 -15
View File
@@ -189,7 +189,7 @@ impl Scheme for IrqScheme {
}
Handle::Avail(cpu_id, data.into_bytes(), AtomicUsize::new(0))
} else if path_str.chars().next() == Some('/') {
} else if path_str.starts_with('/') {
let path_str = &path_str[1..];
Self::open_ext_irq(flags, cpu_id, path_str)?
} else {
@@ -227,7 +227,7 @@ impl Scheme for IrqScheme {
Ok(0)
}
} else {
return Err(Error::new(EINVAL));
Err(Error::new(EINVAL))
}
&Handle::Bsp => {
if buffer.len() < mem::size_of::<usize>() {
@@ -237,7 +237,7 @@ impl Scheme for IrqScheme {
unsafe { *(buffer.as_mut_ptr() as *mut usize) = bsp_apic_id as usize; }
Ok(mem::size_of::<usize>())
} else {
return Err(Error::new(EBADFD));
Err(Error::new(EBADFD))
}
}
&Handle::Avail(_, ref buf, ref offset) | &Handle::TopLevel(ref buf, ref offset) => {
@@ -262,7 +262,7 @@ impl Scheme for IrqScheme {
offset.store(new_offset as usize, Ordering::SeqCst);
Ok(new_offset)
}
_ => return Err(Error::new(ESPIPE)),
_ => Err(Error::new(ESPIPE)),
}
}
@@ -285,9 +285,9 @@ impl Scheme for IrqScheme {
Ok(0)
}
} else {
return Err(Error::new(EINVAL));
Err(Error::new(EINVAL))
}
_ => return Err(Error::new(EBADF)),
_ => Err(Error::new(EBADF)),
}
}
@@ -295,8 +295,8 @@ impl Scheme for IrqScheme {
let handles_guard = HANDLES.read();
let handle = handles_guard.as_ref().unwrap().get(&id).ok_or(Error::new(EBADF))?;
match handle {
&Handle::Irq { irq: handle_irq, .. } => {
match *handle {
Handle::Irq { irq: handle_irq, .. } => {
stat.st_mode = MODE_CHR | 0o600;
stat.st_size = mem::size_of::<usize>() as u64;
stat.st_blocks = 1;
@@ -304,7 +304,7 @@ impl Scheme for IrqScheme {
stat.st_ino = handle_irq.into();
stat.st_nlink = 1;
}
&Handle::Bsp => {
Handle::Bsp => {
stat.st_mode = MODE_CHR | 0o400;
stat.st_size = mem::size_of::<usize>() as u64;
stat.st_blocks = 1;
@@ -312,13 +312,13 @@ impl Scheme for IrqScheme {
stat.st_ino = INO_BSP;
stat.st_nlink = 1;
}
&Handle::Avail(cpu_id, ref buf, _) => {
Handle::Avail(cpu_id, ref buf, _) => {
stat.st_mode = MODE_DIR | 0o700;
stat.st_size = buf.len() as u64;
stat.st_ino = INO_AVAIL | u64::from(cpu_id) << 32;
stat.st_nlink = 2;
}
&Handle::TopLevel(ref buf, _) => {
Handle::TopLevel(ref buf, _) => {
stat.st_mode = MODE_DIR | 0o500;
stat.st_size = buf.len() as u64;
stat.st_ino = INO_TOPLEVEL;
@@ -341,10 +341,10 @@ impl Scheme for IrqScheme {
let handle = handles_guard.as_ref().unwrap().get(&id).ok_or(Error::new(EBADF))?;
let scheme_path = match handle {
&Handle::Irq { irq, .. } => format!("irq:{}", irq),
&Handle::Bsp => format!("irq:bsp"),
&Handle::Avail(cpu_id, _, _) => format!("irq:cpu-{:2x}", cpu_id),
&Handle::TopLevel(_, _) => format!("irq:"),
Handle::Irq { irq, .. } => format!("irq:{}", irq),
Handle::Bsp => format!("irq:bsp"),
Handle::Avail(cpu_id, _, _) => format!("irq:cpu-{:2x}", cpu_id),
Handle::TopLevel(_, _) => format!("irq:"),
}.into_bytes();
let mut i = 0;
+2 -2
View File
@@ -53,7 +53,7 @@ impl Scheme for PipeScheme {
// Clone to prevent deadlocks
let pipe = {
let pipes = PIPES.read();
pipes.0.get(&id).map(|pipe| pipe.clone()).ok_or(Error::new(EBADF))?
pipes.0.get(&id).cloned().ok_or(Error::new(EBADF))?
};
pipe.read(buf)
@@ -63,7 +63,7 @@ impl Scheme for PipeScheme {
// Clone to prevent deadlocks
let pipe = {
let pipes = PIPES.read();
pipes.1.get(&id).map(|pipe| pipe.clone()).ok_or(Error::new(EBADF))?
pipes.1.get(&id).cloned().ok_or(Error::new(EBADF))?
};
pipe.write(buf)
+10 -10
View File
@@ -366,7 +366,7 @@ impl ProcScheme {
let mut data = String::new();
for index in target.files.read().iter().enumerate().filter_map(|(idx, val)| val.as_ref().map(|_| idx)) {
write!(data, "{}\n", index).unwrap();
writeln!(data, "{}", index).unwrap();
}
data.into_bytes().into_boxed_slice()
}));
@@ -624,8 +624,8 @@ impl Scheme for ProcScheme {
// in that case, what scheme?
b"empty" => (Operation::AddrSpace { addrspace: new_addrspace()? }, false),
b"exclusive" => (Operation::AddrSpace { addrspace: addrspace.write().try_clone()? }, false),
b"mem" => (Operation::Memory { addrspace: Arc::clone(&addrspace) }, true),
b"mmap-min-addr" => (Operation::MmapMinAddr(Arc::clone(&addrspace)), false),
b"mem" => (Operation::Memory { addrspace: Arc::clone(addrspace) }, true),
b"mmap-min-addr" => (Operation::MmapMinAddr(Arc::clone(addrspace)), false),
grant_handle if grant_handle.starts_with(b"grant-") => {
let start_addr = usize::from_str_radix(core::str::from_utf8(&grant_handle[6..]).map_err(|_| Error::new(EINVAL))?, 16).map_err(|_| Error::new(EINVAL))?;
@@ -742,7 +742,7 @@ impl Scheme for ProcScheme {
Ok((Output { float: context.get_fx_regs() }, mem::size_of::<FloatRegisters>()))
})?,
RegsKind::Int => try_stop_context(info.pid, |context| match unsafe { ptrace::regs_for(&context) } {
RegsKind::Int => try_stop_context(info.pid, |context| match unsafe { ptrace::regs_for(context) } {
None => {
assert!(!context.running, "try_stop_context is broken, clearly");
println!("{}:{}: Couldn't read registers from stopped process", file!(), line!());
@@ -838,7 +838,7 @@ impl Scheme for ProcScheme {
// TODO: Find a better way to switch address spaces, since they also require switching
// the instruction and stack pointer. Maybe remove `<pid>/regs` altogether and replace it
// with `<pid>/ctx`
_ => return Err(Error::new(EBADF)),
_ => Err(Error::new(EBADF)),
}
}
@@ -1043,7 +1043,7 @@ impl Scheme for ProcScheme {
}
Ok(buf.len())
}
Operation::Filetable { .. } => return Err(Error::new(EBADF)),
Operation::Filetable { .. } => Err(Error::new(EBADF)),
Operation::CurrentFiletable => {
let filetable_fd = usize::from_ne_bytes(<[u8; mem::size_of::<usize>()]>::try_from(buf).map_err(|_| Error::new(EINVAL))?);
@@ -1081,7 +1081,7 @@ impl Scheme for ProcScheme {
addrspace.write().mmap_min = val;
Ok(mem::size_of::<usize>())
}
_ => return Err(Error::new(EBADF)),
_ => Err(Error::new(EBADF)),
}
}
@@ -1135,7 +1135,7 @@ impl Scheme for ProcScheme {
_ => return Err(Error::new(EOPNOTSUPP)),
});
read_from(buf, &path.as_bytes(), &mut 0)
read_from(buf, path.as_bytes(), &mut 0)
}
fn fstat(&self, id: usize, stat: &mut Stat) -> Result<usize> {
@@ -1328,14 +1328,14 @@ impl KernelScheme for ProcScheme {
if let Some(before) = before { src_addr_space.grants.insert(before); }
if let Some(after) = after { src_addr_space.grants.insert(after); }
dst_addr_space.mmap(requested_dst_page, grant_page_count, map.flags, |dst_page, _flags, dst_mapper, dst_flusher| Ok(Grant::transfer(middle, dst_page, src_mapper, dst_mapper, InactiveFlusher::new(), dst_flusher)?))?
dst_addr_space.mmap(requested_dst_page, grant_page_count, map.flags, |dst_page, _flags, dst_mapper, dst_flusher| Grant::transfer(middle, dst_page, src_mapper, dst_mapper, InactiveFlusher::new(), dst_flusher))?
} else {
dst_addr_space.mmap(requested_dst_page, grant_page_count, map.flags, |dst_page, flags, dst_mapper, flusher| Ok(Grant::borrow(Page::containing_address(src_grant_region.start_address()), dst_page, grant_page_count, flags, None, src_mapper, dst_mapper, flusher)?))?
};
Ok(result_page.start_address().data())
}
_ => return Err(Error::new(EBADF)),
_ => Err(Error::new(EBADF)),
}
}
}
+1 -1
View File
@@ -79,7 +79,7 @@ impl Scheme for RootScheme {
let context = {
let contexts = context::contexts();
let context = contexts.current().ok_or(Error::new(ESRCH))?;
Arc::downgrade(&context)
Arc::downgrade(context)
};
let id = self.next_id.fetch_add(1, Ordering::SeqCst);
+1 -1
View File
@@ -93,7 +93,7 @@ impl Scheme for SysScheme {
let data = entry.1()?;
self.handles.write().insert(id, Handle {
path: entry.0,
data: data,
data,
mode: MODE_FILE | 0o444,
seek: 0
});
+1 -1
View File
@@ -15,7 +15,7 @@ pub fn resource() -> Result<Vec<u8>> {
let contexts = context::contexts();
for (id, context_lock) in contexts.iter() {
let context = context_lock.read();
rows.push((*id, context.name.read().clone(), context.syscall.clone()));
rows.push((*id, context.name.read().clone(), context.syscall));
}
}
+8 -10
View File
@@ -298,16 +298,14 @@ impl UserInner {
// TODO: Faster, cleaner mechanism to get descriptor
let scheme = self.scheme_id.load(Ordering::SeqCst);
let mut desc_res = Err(Error::new(EBADF));
for context_file_opt in context.files.read().iter() {
if let Some(context_file) = context_file_opt {
let (context_scheme, context_number) = {
let desc = context_file.description.read();
(desc.scheme, desc.number)
};
if context_scheme == scheme && context_number == file {
desc_res = Ok(context_file.clone());
break;
}
for context_file in context.files.read().iter().flatten() {
let (context_scheme, context_number) = {
let desc = context_file.description.read();
(desc.scheme, desc.number)
};
if context_scheme == scheme && context_number == file {
desc_res = Ok(context_file.clone());
break;
}
}
let desc = desc_res?;