Skip to content

Commit 0476db6

Browse files
misc(kernel): cleanup
Signed-off-by: Anhad Singh <[email protected]>
1 parent d7f9d43 commit 0476db6

File tree

22 files changed

+54
-76
lines changed

22 files changed

+54
-76
lines changed

src/aero_kernel/src/arch/x86_64/apic.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use crate::utils::sync::{Mutex, MutexGuard};
2929
use super::{io, time};
3030

3131
use crate::acpi::madt;
32-
use crate::PHYSICAL_MEMORY_OFFSET;
3332

3433
const APIC_SPURIOUS_VECTOR: u32 = 0xFF;
3534

src/aero_kernel/src/drivers/block/nvme/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod queue;
2121
use core::mem::MaybeUninit;
2222

2323
use command::*;
24-
use queue::*;
24+
use queue::QueuePair;
2525

2626
use alloc::sync::Arc;
2727
use alloc::vec::Vec;
@@ -281,8 +281,8 @@ impl<'a> Controller<'a> {
281281
let bar0 = header.get_bar(0).ok_or(Error::UnknownBar)?;
282282

283283
// All NVMe registers are accessible via BAR0.
284-
let (registers_addr, bar_size) = match bar0 {
285-
Bar::Memory64 { address, size, .. } => (PhysAddr::new(address), size),
284+
let registers_addr = match bar0 {
285+
Bar::Memory64 { address, .. } => PhysAddr::new(address),
286286
_ => return Err(Error::UnknownBar),
287287
};
288288

@@ -538,7 +538,7 @@ impl PciDeviceHandle for Handler<'static> {
538538

539539
for device_name in devices {
540540
let device = BlockDevice::new(device_name, controller.clone());
541-
install_block_device(device).expect("nvme: failed to install the block device")
541+
install_block_device(device).expect("nvme: failed to install the block device");
542542
}
543543

544544
self.controllers.lock().push(controller);
@@ -551,7 +551,7 @@ fn irq_handler(_stack: &mut InterruptStack) {
551551

552552
fn nvme_init() {
553553
// Register the NVMe device handler.
554-
register_device_driver(Handler::new())
554+
register_device_driver(Handler::new());
555555
}
556556

557557
crate::module_init!(nvme_init, ModuleType::Block);

src/aero_kernel/src/drivers/pci.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,9 @@ impl PciHeader {
679679

680680
// bit 0:true - the BAR is in memory
681681
// bit 0:false - the BAR is in I/O
682-
if !bar.get_bit(0) {
682+
if bar.get_bit(0) {
683+
Some(Bar::IO(bar.get_bits(2..32)))
684+
} else {
683685
let prefetchable = bar.get_bit(3);
684686
let address = bar.get_bits(4..32) << 4;
685687

@@ -727,8 +729,6 @@ impl PciHeader {
727729

728730
_ => None,
729731
}
730-
} else {
731-
Some(Bar::IO(bar.get_bits(2..32)))
732732
}
733733
}
734734

src/aero_kernel/src/drivers/pty.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use alloc::sync::{Arc, Weak};
2626
use alloc::vec::Vec;
2727
use spin::{Once, RwLock};
2828

29-
use uapi::pty::*;
29+
use uapi::pty::TIOCGPTN;
3030

3131
use crate::arch::user_copy::UserRef;
3232
use crate::fs::cache::*;
@@ -107,8 +107,6 @@ struct Master {
107107

108108
impl Master {
109109
pub fn new() -> Self {
110-
use aero_syscall::*;
111-
112110
Self {
113111
id: PTY_ID.fetch_add(1, Ordering::SeqCst),
114112
wq: WaitQueue::new(),
@@ -191,8 +189,8 @@ impl TerminalDevice for Slave {
191189
}
192190

193191
fn detach(&self, task: Arc<Task>) {
194-
use aero_syscall::signal::*;
195-
use aero_syscall::*;
192+
use aero_syscall::signal::SIGINT;
193+
use aero_syscall::VINTR;
196194

197195
if !self.master.discipline.termios.lock().is_cooked() {
198196
return;

src/aero_kernel/src/drivers/uart_16550.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bitflags::bitflags! {
4747
pub struct SerialPort(u16);
4848

4949
impl SerialPort {
50-
#[inline(always)]
50+
#[inline]
5151
pub const fn new(port: u16) -> Self {
5252
Self(port)
5353
}
@@ -90,7 +90,7 @@ impl SerialPort {
9090

9191
fn wait_for_line_status(&self, line_status: LineStatus) {
9292
while !self.line_status().contains(line_status) {
93-
core::hint::spin_loop()
93+
core::hint::spin_loop();
9494
}
9595
}
9696

src/aero_kernel/src/fs/block/gpt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use core::mem::MaybeUninit;
2323
use alloc::boxed::Box;
2424
use alloc::sync::Arc;
2525

26-
const GPT_TABLE_SIGNATURE: u64 = 0x5452415020494645;
26+
const GPT_TABLE_SIGNATURE: u64 = 0x5452_4150_2049_4645;
2727

2828
#[repr(C)]
2929
pub struct GptTableHeader {

src/aero_kernel/src/fs/inode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ pub trait INodeInterface: Send + Sync {
286286
}
287287

288288
/// Structure representing the crucial, characteristics of an inode. The metadata
289-
/// of an inode can be retrieved by invoking the [INodeInterface::metadata] function.
289+
/// of an inode can be retrieved by invoking the [`INodeInterface::metadata`] function.
290290
#[derive(Debug, Copy, Clone)]
291291
pub struct Metadata {
292292
pub id: usize,
@@ -345,7 +345,7 @@ pub enum FileContents {
345345
/// and is backed by a static byte buffer
346346
StaticContent(&'static [u8]),
347347

348-
/// If the file type of the inode is [FileType::Device], in that case this variant
348+
/// If the file type of the inode is [`FileType::Device`], in that case this variant
349349
/// is used.
350350
Device(Arc<DevINode>),
351351

src/aero_kernel/src/fs/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl PathBuf {
138138
self.as_mut_vec().truncate(0);
139139
}
140140

141-
let need_sep = self.0.chars().last().map(|c| c != '/').unwrap_or(false);
141+
let need_sep = self.0.chars().last().is_some_and(|c| c != '/');
142142

143143
// TODO: verbatim pahts need . and .. removed
144144

src/aero_kernel/src/mem/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ mod vmalloc;
2323

2424
use ::alloc::boxed::Box;
2525

26-
use crate::mem::paging::*;
27-
28-
use self::paging::{active_level_4_table, FRAME_ALLOCATOR};
26+
use paging::*;
2927

3028
/// Structure representing a *virtual* address space. The address space
3129
/// contains a reference of the page table allocated for this address space.

src/aero_kernel/src/mem/paging/addr.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ impl VirtAddr {
9797
/// Converts the address to a raw pointer.
9898
#[cfg(target_pointer_width = "64")]
9999
#[inline]
100-
pub fn as_ptr<T>(self) -> *const T {
100+
pub const fn as_ptr<T>(self) -> *const T {
101101
self.as_u64() as *const T
102102
}
103103

104104
/// Converts the address to a mutable raw pointer.
105105
#[cfg(target_pointer_width = "64")]
106106
#[inline]
107-
pub fn as_mut_ptr<T>(self) -> *mut T {
108-
self.as_ptr::<T>() as *mut T
107+
pub const fn as_mut_ptr<T>(self) -> *mut T {
108+
self.as_ptr::<T>().cast_mut()
109109
}
110110

111111
#[inline]
112-
pub fn is_zero(self) -> bool {
112+
pub const fn is_zero(self) -> bool {
113113
self.0 == 0
114114
}
115115

@@ -360,12 +360,6 @@ impl Step for VirtAddr {
360360
}
361361
}
362362

363-
/// A passed `u64` was not a valid physical address.
364-
///
365-
/// This means that bits 52 to 64 were not all null.
366-
#[derive(Debug)]
367-
pub struct PhysAddrNotValid(u64);
368-
369363
impl PhysAddr {
370364
/// Creates a new physical address.
371365
///
@@ -570,7 +564,7 @@ pub fn align_down(addr: u64, align: u64) -> u64 {
570564
/// Panics if the alignment is not a power of two. Without the `const_fn`
571565
/// feature, the panic message will be "index out of bounds".
572566
#[inline]
573-
pub fn align_up(addr: u64, align: u64) -> u64 {
567+
pub const fn align_up(addr: u64, align: u64) -> u64 {
574568
let align_mask = align - 1;
575569

576570
if addr & align_mask == 0 {
@@ -581,7 +575,7 @@ pub fn align_up(addr: u64, align: u64) -> u64 {
581575
}
582576

583577
#[inline]
584-
pub fn is_aligned(addr: u64, align: u64) -> bool {
578+
pub const fn is_aligned(addr: u64, align: u64) -> bool {
585579
align_up(addr, align) == addr
586580
}
587581

0 commit comments

Comments
 (0)