refactor: clean up non-doc warnings

This commit is contained in:
2021-10-26 13:37:44 +03:00
parent 8274abbda1
commit 4656bb13f4
10 changed files with 53 additions and 29 deletions
+9 -9
View File
@@ -75,12 +75,12 @@ fn dump_node(level: Level, node: &INode, depth: usize) {
fn find_node<'a>(at: INode<'a>, path: &str) -> Option<INode<'a>> {
let (item, path) = path_component_left(path);
if item == "" {
if item.is_empty() {
assert_eq!(path, "");
Some(at)
} else {
let child = at.children().find(|c| c.name().unwrap() == item)?;
if path == "" {
if path.is_empty() {
Some(child)
} else {
find_node(child, path)
@@ -92,13 +92,13 @@ fn find_prop<'a>(at: INode<'a>, name: &str) -> Option<IProp<'a>> {
at.props().find(|p| p.name().unwrap() == name)
}
fn read_cells(prop: &IProp, off: usize, cells: u32) -> Option<u64> {
Some(match cells {
1 => prop.u32(off).ok()? as u64,
2 => (prop.u32(off).ok()? as u64) | ((prop.u32(off + 1).ok()? as u64) << 32),
_ => todo!(),
})
}
// fn read_cells(prop: &IProp, off: usize, cells: u32) -> Option<u64> {
// Some(match cells {
// 1 => prop.u32(off).ok()? as u64,
// 2 => (prop.u32(off).ok()? as u64) | ((prop.u32(off + 1).ok()? as u64) << 32),
// _ => todo!(),
// })
// }
impl DeviceTree {
pub fn dump(&self, level: Level) {
+7 -3
View File
@@ -1,6 +1,9 @@
#![allow(missing_docs)]
use crate::mem::{self, phys::{self, PageUsage}};
use crate::mem::{
self,
phys::{self, PageUsage},
};
use memfs::BlockAllocator;
#[derive(Clone, Copy)]
@@ -8,7 +11,7 @@ pub struct MemfsBlockAlloc;
unsafe impl BlockAllocator for MemfsBlockAlloc {
fn alloc(&self) -> *mut u8 {
if let Ok(page) = phys::alloc_page(PageUsage::Kernel) {
if let Ok(page) = phys::alloc_page(PageUsage::Filesystem) {
mem::virtualize(page) as *mut u8
} else {
core::ptr::null_mut()
@@ -16,6 +19,7 @@ unsafe impl BlockAllocator for MemfsBlockAlloc {
}
unsafe fn dealloc(&self, data: *mut u8) {
todo!()
let phys = (data as usize) - mem::KERNEL_OFFSET;
phys::free_page(phys).unwrap();
}
}
+2 -2
View File
@@ -19,9 +19,9 @@ impl SimpleManager {
let pages: &'static mut [PageInfo] =
core::slice::from_raw_parts_mut(virtualize(at) as *mut _, count);
// Initialize uninit pages
for index in 0..count {
for entry in pages.iter_mut() {
mem::forget(mem::replace(
&mut pages[index],
entry,
PageInfo {
refcount: 0,
usage: PageUsage::Reserved,
+7
View File
@@ -29,6 +29,8 @@ pub enum PageUsage {
Paging,
/// Userspace page
UserPrivate,
/// Filesystem data and blocks
Filesystem,
}
/// Data structure representing a single physical memory page
@@ -79,6 +81,11 @@ pub fn alloc_page(pu: PageUsage) -> Result<usize, Errno> {
MANAGER.lock().as_mut().unwrap().alloc_page(pu)
}
/// Releases a single physical memory page back for further allocation.
pub unsafe fn free_page(page: usize) -> Result<(), Errno> {
MANAGER.lock().as_mut().unwrap().free_page(page)
}
fn find_contiguous<T: Iterator<Item = MemoryRegion>>(iter: T, count: usize) -> Option<usize> {
for region in iter {
let mut collected = 0;
+3 -1
View File
@@ -67,7 +67,9 @@ pub unsafe fn enter(initrd: Option<(usize, usize)>) -> ! {
let size = end - start;
infoln!("Constructing initrd filesystem in memory, this may take a while...");
let fs = Ramfs::open(start as *mut u8, size, MemfsBlockAlloc {}).unwrap();
let fs = unsafe {
Ramfs::open(start as *mut u8, size, MemfsBlockAlloc {}).unwrap()
};
infoln!("Done constructing ramfs");
let root = fs.root().unwrap();
let ioctx = Ioctx::new(root);
+3 -5
View File
@@ -48,11 +48,9 @@ impl<T> IrqSafeSpinLock<T> {
cortex_a::asm::wfe();
}
unsafe {
IrqSafeSpinLockGuard {
lock: self,
irq_state
}
IrqSafeSpinLockGuard {
lock: self,
irq_state
}
}
}