Skip to content

Commit

Permalink
trivial: fix clippy lints
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Cross <[email protected]>
  • Loading branch information
Dan Cross committed Sep 27, 2024
1 parent 1d95064 commit 9c2b970
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 28 deletions.
8 changes: 5 additions & 3 deletions aarch64/src/devcons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,10 +37,11 @@ pub fn init(dt: &DeviceTree) {
let uart = MiniUart::new(dt, KZERO);
uart.init();

static mut UART: MaybeUninit<MiniUart> = MaybeUninit::uninit();
static UART: SyncUnsafeCell<MaybeUninit<MiniUart>> = SyncUnsafeCell::new(MaybeUninit::uninit());
unsafe {
UART.write(uart);
UART.assume_init_mut()
let cons = &mut *UART.get();
cons.write(uart);
cons.assume_init_mut()
}
});
}
8 changes: 5 additions & 3 deletions aarch64/src/mailbox.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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<Mailbox> = MaybeUninit::uninit();
static MAYBE_MAILBOX: SyncUnsafeCell<MaybeUninit<Mailbox>> = 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()
}
});
}
Expand Down
1 change: 1 addition & 0 deletions aarch64/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 14 additions & 12 deletions port/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -55,7 +57,7 @@ impl Block {
}

/// Returns the length of the region.
pub fn len(self) -> usize {
fn len(self) -> usize {
self.len
}
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion port/src/fdt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::too_long_first_doc_paragraph)]

use core::{
ffi::CStr,
mem::{self, MaybeUninit},
Expand Down Expand Up @@ -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)
})
}

Expand Down
1 change: 1 addition & 0 deletions riscv64/src/main.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
9 changes: 5 additions & 4 deletions riscv64/src/platform/virt/devcons.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Racy to start.

use core::cell::SyncUnsafeCell;
use core::mem::MaybeUninit;

use crate::uart16550::Uart16550;
Expand All @@ -17,11 +18,11 @@ pub fn init(dt: &DeviceTree) {
let mut uart = Uart16550::new(ns16550a_reg);
uart.init(115_200);

static mut UART: MaybeUninit<Uart16550> = MaybeUninit::uninit();

static CONS: SyncUnsafeCell<MaybeUninit<Uart16550>> = SyncUnsafeCell::new(MaybeUninit::uninit());
unsafe {
UART.write(uart);
UART.assume_init_mut()
let cons = &mut *CONS.get();
cons.write(uart);
cons.assume_init_mut()
}
});
}
4 changes: 2 additions & 2 deletions x86_64/src/devcons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Uart for Uart16550 {

pub fn init() {
Console::new(|| {
static UART: SyncUnsafeCell<Uart16550> = SyncUnsafeCell::new(Uart16550 { port: 0x3f8 });
unsafe { &mut *UART.get() }
static CONS: SyncUnsafeCell<Uart16550> = SyncUnsafeCell::new(Uart16550 { port: 0x3f8 });
unsafe { &mut *CONS.get() }
});
}
2 changes: 1 addition & 1 deletion x86_64/src/uart16550.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Simple UART driver to get setarted.
//! Simple UART driver to get setarted.
pub fn putb(port: u16, b: u8) {
unsafe {
Expand Down
2 changes: 0 additions & 2 deletions xtask/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>>,
Expand Down

0 comments on commit 9c2b970

Please sign in to comment.