From 9c2b970b65c82a538a943dba5a7389be169150e0 Mon Sep 17 00:00:00 2001 From: Dan Cross Date: Fri, 27 Sep 2024 16:52:10 +0000 Subject: [PATCH] trivial: fix clippy lints Signed-off-by: Dan Cross --- aarch64/src/devcons.rs | 8 +++++--- aarch64/src/mailbox.rs | 8 +++++--- aarch64/src/main.rs | 1 + port/src/allocator.rs | 26 ++++++++++++++------------ port/src/fdt.rs | 4 +++- riscv64/src/main.rs | 1 + riscv64/src/platform/virt/devcons.rs | 9 +++++---- x86_64/src/devcons.rs | 4 ++-- x86_64/src/uart16550.rs | 2 +- xtask/src/config.rs | 2 -- 10 files changed, 37 insertions(+), 28 deletions(-) diff --git a/aarch64/src/devcons.rs b/aarch64/src/devcons.rs index 802b583..1e3fb58 100644 --- a/aarch64/src/devcons.rs +++ b/aarch64/src/devcons.rs @@ -2,6 +2,7 @@ use crate::param::KZERO; use crate::uartmini::MiniUart; +use core::cell::SyncUnsafeCell; use core::mem::MaybeUninit; use port::devcons::Console; use port::fdt::DeviceTree; @@ -36,10 +37,11 @@ pub fn init(dt: &DeviceTree) { let uart = MiniUart::new(dt, KZERO); uart.init(); - static mut UART: MaybeUninit = MaybeUninit::uninit(); + static UART: SyncUnsafeCell> = SyncUnsafeCell::new(MaybeUninit::uninit()); unsafe { - UART.write(uart); - UART.assume_init_mut() + let cons = &mut *UART.get(); + cons.write(uart); + cons.assume_init_mut() } }); } diff --git a/aarch64/src/mailbox.rs b/aarch64/src/mailbox.rs index 0f0f794..2bf4171 100644 --- a/aarch64/src/mailbox.rs +++ b/aarch64/src/mailbox.rs @@ -1,5 +1,6 @@ use crate::io::{read_reg, write_reg}; use crate::param::KZERO; +use core::cell::SyncUnsafeCell; use core::mem::MaybeUninit; use port::fdt::DeviceTree; use port::mcslock::{Lock, LockNode}; @@ -21,10 +22,11 @@ pub fn init(dt: &DeviceTree) { let node = LockNode::new(); let mut mailbox = MAILBOX.lock(&node); *mailbox = Some({ - static mut MAYBE_MAILBOX: MaybeUninit = MaybeUninit::uninit(); + static MAYBE_MAILBOX: SyncUnsafeCell> = SyncUnsafeCell::new(MaybeUninit::uninit()); unsafe { - MAYBE_MAILBOX.write(Mailbox::new(dt, KZERO)); - MAYBE_MAILBOX.assume_init_mut() + let maybe_mailbox = &mut *MAYBE_MAILBOX.get(); + maybe_mailbox.write(Mailbox::new(dt, KZERO)); + maybe_mailbox.assume_init_mut() } }); } diff --git a/aarch64/src/main.rs b/aarch64/src/main.rs index 70f317e..f568900 100644 --- a/aarch64/src/main.rs +++ b/aarch64/src/main.rs @@ -5,6 +5,7 @@ #![feature(alloc_error_handler)] #![feature(core_intrinsics)] #![feature(strict_provenance)] +#![feature(sync_unsafe_cell)] #![forbid(unsafe_op_in_unsafe_fn)] mod devcons; diff --git a/port/src/allocator.rs b/port/src/allocator.rs index 6db7267..211d1b6 100644 --- a/port/src/allocator.rs +++ b/port/src/allocator.rs @@ -5,6 +5,8 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. +#![allow(clippy::too_long_first_doc_paragraph)] + use alloc::alloc::{AllocError, Allocator, Layout}; use core::ptr::NonNull; use core::sync::atomic::{AtomicUsize, Ordering}; @@ -55,7 +57,7 @@ impl Block { } /// Returns the length of the region. - pub fn len(self) -> usize { + fn len(self) -> usize { self.len } } @@ -115,17 +117,17 @@ unsafe impl Allocator for BumpAlloc { } } -/// # QuickFit allocator for small objects. -/// -/// This is an implementation of the QuickFit[Wei88] allocator -/// for small objects, suitable for managing small heaps in -/// memory constrained environments, such as boot loaders and -/// standalone debuggers. -/// -/// [Wei88] Charles B. Weinstock and William A. Wulf. 1988. -/// Quick Fit: An Efficient Algorithm for Heap Storage -/// Allocation. ACM SIGPLAN Notices 23, 10 (Oct. 1988), -/// 141-148. https://doi.org/10.1145/51607.51619 +// # QuickFit allocator for small objects. +// +// This is an implementation of the QuickFit[Wei88] allocator +// for small objects, suitable for managing small heaps in +// memory constrained environments, such as boot loaders and +// standalone debuggers. +// +// [Wei88] Charles B. Weinstock and William A. Wulf. 1988. +// Quick Fit: An Efficient Algorithm for Heap Storage +// Allocation. ACM SIGPLAN Notices 23, 10 (Oct. 1988), +// 141-148. https://doi.org/10.1145/51607.51619 const ALLOC_UNIT_SHIFT: usize = 6; const ALLOC_UNIT_SIZE: usize = 1 << ALLOC_UNIT_SHIFT; diff --git a/port/src/fdt.rs b/port/src/fdt.rs index 75773e1..0a9f4a4 100644 --- a/port/src/fdt.rs +++ b/port/src/fdt.rs @@ -1,3 +1,5 @@ +#![allow(clippy::too_long_first_doc_paragraph)] + use core::{ ffi::CStr, mem::{self, MaybeUninit}, @@ -173,7 +175,7 @@ impl<'a> DeviceTree<'a> { } let (start, end) = (value_i, value_i + 4); value_i = end; - return self.structs().get(start..end).and_then(bytes_to_u32); + self.structs().get(start..end).and_then(bytes_to_u32) }) } diff --git a/riscv64/src/main.rs b/riscv64/src/main.rs index 8551859..d569675 100644 --- a/riscv64/src/main.rs +++ b/riscv64/src/main.rs @@ -1,4 +1,5 @@ #![feature(alloc_error_handler)] +#![feature(sync_unsafe_cell)] #![cfg_attr(not(any(test)), no_std)] #![cfg_attr(not(test), no_main)] #![allow(clippy::upper_case_acronyms)] diff --git a/riscv64/src/platform/virt/devcons.rs b/riscv64/src/platform/virt/devcons.rs index 49f2e73..acdbd74 100644 --- a/riscv64/src/platform/virt/devcons.rs +++ b/riscv64/src/platform/virt/devcons.rs @@ -1,5 +1,6 @@ // Racy to start. +use core::cell::SyncUnsafeCell; use core::mem::MaybeUninit; use crate::uart16550::Uart16550; @@ -17,11 +18,11 @@ pub fn init(dt: &DeviceTree) { let mut uart = Uart16550::new(ns16550a_reg); uart.init(115_200); - static mut UART: MaybeUninit = MaybeUninit::uninit(); - + static CONS: SyncUnsafeCell> = SyncUnsafeCell::new(MaybeUninit::uninit()); unsafe { - UART.write(uart); - UART.assume_init_mut() + let cons = &mut *CONS.get(); + cons.write(uart); + cons.assume_init_mut() } }); } diff --git a/x86_64/src/devcons.rs b/x86_64/src/devcons.rs index b4c2781..6493411 100644 --- a/x86_64/src/devcons.rs +++ b/x86_64/src/devcons.rs @@ -15,7 +15,7 @@ impl Uart for Uart16550 { pub fn init() { Console::new(|| { - static UART: SyncUnsafeCell = SyncUnsafeCell::new(Uart16550 { port: 0x3f8 }); - unsafe { &mut *UART.get() } + static CONS: SyncUnsafeCell = SyncUnsafeCell::new(Uart16550 { port: 0x3f8 }); + unsafe { &mut *CONS.get() } }); } diff --git a/x86_64/src/uart16550.rs b/x86_64/src/uart16550.rs index fb177c5..6641735 100644 --- a/x86_64/src/uart16550.rs +++ b/x86_64/src/uart16550.rs @@ -1,4 +1,4 @@ -/// Simple UART driver to get setarted. +//! Simple UART driver to get setarted. pub fn putb(port: u16, b: u8) { unsafe { diff --git a/xtask/src/config.rs b/xtask/src/config.rs index 09539be..3c20841 100644 --- a/xtask/src/config.rs +++ b/xtask/src/config.rs @@ -46,8 +46,6 @@ pub struct Build { /// #[cfg(dev_foo = "baz")] /// pub mod foobaz; /// ``` - -/// config section #[derive(Debug, Serialize, Deserialize)] pub struct Config { pub dev: Option>,