Skip to content

Commit

Permalink
Refactor with clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
lemolatoon committed Nov 18, 2023
1 parent 5acee02 commit d68677b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 0 additions & 2 deletions kernel-lib/src/allocator/bump_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ unsafe impl BoundaryAlloc for crate::mutex::Mutex<BumpAllocator> {
unsafe fn alloc(&self, layout: core::alloc::Layout, boundary: usize) -> *mut u8 {
let mut allocator = crate::lock!(self);
let Ok(alloc_start) = align_and_boundary_to(allocator.next, layout, boundary) else {
panic!("Allocation failed: {:?}", layout);
return core::ptr::null_mut();
};

if alloc_start.end >= allocator.heap_end {
panic!("Allocation failed: {:?}", layout);
return core::ptr::null_mut();
}

Expand Down
6 changes: 4 additions & 2 deletions kernel/src/alloc/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ use alloc::boxed::Box;
use core::mem::MaybeUninit;
use kernel_lib::{allocator::bump_allocator::BumpAllocator, mutex::Mutex};

const HEAP_SIZE: usize = 1 << 21;

pub type GlobalAllocator = Mutex<BumpAllocator>;

#[global_allocator]
static ALLOCATOR: GlobalAllocator = Mutex::new(BumpAllocator::new());

/// Initialize the global allocator.
/// # Safety
/// The caller must ensure that the given heap range is unused permanently.
/// Also, this method must be called only once. before any allocation.
pub unsafe fn init_allocator(heap_start: usize, heap_end: usize) {
log::debug!(
"Initializing allocator: {:#x} - {:#x}",
Expand Down
6 changes: 3 additions & 3 deletions kernel/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub static LAYER_MANGER: Mutex<OnceCell<LayerManager<'static>>> = Mutex::new(Onc
#[macro_export]
macro_rules! lock_layer_manager {
() => {
kernel_lib::lock!(crate::graphics::LAYER_MANGER)
kernel_lib::lock!($crate::graphics::LAYER_MANGER)
.get()
.unwrap()
};
Expand All @@ -351,7 +351,7 @@ macro_rules! lock_layer_manager {
#[macro_export]
macro_rules! lock_layer_manager_mut {
() => {
kernel_lib::lock!(crate::graphics::LAYER_MANGER)
kernel_lib::lock!($crate::graphics::LAYER_MANGER)
.get_mut()
.unwrap()
};
Expand All @@ -360,6 +360,6 @@ macro_rules! lock_layer_manager_mut {
#[macro_export]
macro_rules! lock_layer_manager_raw {
() => {
kernel_lib::lock!(crate::graphics::LAYER_MANGER)
kernel_lib::lock!($crate::graphics::LAYER_MANGER)
};
}
3 changes: 3 additions & 0 deletions kernel/src/usb/class_driver/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pub const fn mouse() -> CallbackType {
}

/// This function must be called before any other functions that use MOUSE_LAYER_ID.
/// # Safety
/// This method must be called before mouse driver is initialized.
/// Also, this method must be called only once.
pub unsafe fn init_mouse_cursor_layer() -> LayerId {
let window = Window::new(
MOUSE_CURSOR_SHAPE.get_width(),
Expand Down

0 comments on commit d68677b

Please sign in to comment.