TimerService: clippy findings

Change-Id: I024582343a38760d4c83b9b78c783ea170dff1b4
GitOrigin-RevId: 24315ccd139f19ced79aaf6703530f6e56437c3c
This commit is contained in:
Sam Leffler 2022-05-13 15:02:01 +00:00
parent 588fb66af6
commit c4563fabfb
2 changed files with 46 additions and 52 deletions

View File

@ -1,5 +1,6 @@
//! The Timer Service provides multiplexed access to a hardware timer. //! The Timer Service provides multiplexed access to a hardware timer.
#![no_std] #![no_std]
#![allow(clippy::missing_safety_doc)]
use core::time::Duration; use core::time::Duration;
use kata_os_common::allocator; use kata_os_common::allocator;
@ -10,14 +11,13 @@ use kata_timer_service::TIMER_SRV;
use log::trace; use log::trace;
#[no_mangle] #[no_mangle]
pub extern "C" fn pre_init() { pub unsafe extern "C" fn pre_init() {
static KATA_LOGGER: KataLogger = KataLogger; static KATA_LOGGER: KataLogger = KataLogger;
log::set_logger(&KATA_LOGGER).unwrap(); log::set_logger(&KATA_LOGGER).unwrap();
log::set_max_level(log::LevelFilter::Trace); log::set_max_level(log::LevelFilter::Trace);
// TODO(jesionowski): temp until we integrate with seL4 // TODO(jesionowski): temp until we integrate with seL4
static mut HEAP_MEMORY: [u8; 4 * 1024] = [0; 4 * 1024]; static mut HEAP_MEMORY: [u8; 4 * 1024] = [0; 4 * 1024];
unsafe {
allocator::ALLOCATOR.init(HEAP_MEMORY.as_mut_ptr() as usize, HEAP_MEMORY.len()); allocator::ALLOCATOR.init(HEAP_MEMORY.as_mut_ptr() as usize, HEAP_MEMORY.len());
trace!( trace!(
"setup heap: start_addr {:p} size {}", "setup heap: start_addr {:p} size {}",
@ -25,32 +25,29 @@ pub extern "C" fn pre_init() {
HEAP_MEMORY.len() HEAP_MEMORY.len()
); );
} }
}
#[no_mangle] #[no_mangle]
pub extern "C" fn timer__init() { pub unsafe extern "C" fn timer__init() {
unsafe {
TIMER_SRV.lock().init(); TIMER_SRV.lock().init();
} }
}
extern "C" { extern "C" {
fn timer_get_sender_id() -> seL4_Word; fn timer_get_sender_id() -> seL4_Word;
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn timer_completed_timers() -> u32 { pub unsafe extern "C" fn timer_completed_timers() -> u32 {
unsafe {
let client_id = timer_get_sender_id(); let client_id = timer_get_sender_id();
return TIMER_SRV.lock().completed_timers(client_id); return TIMER_SRV.lock().completed_timers(client_id);
} }
}
#[no_mangle] #[no_mangle]
pub extern "C" fn timer_oneshot(timer_id: TimerId, duration_ms: u32) -> TimerServiceError { pub unsafe extern "C" fn timer_oneshot(
timer_id: TimerId,
duration_ms: u32
) -> TimerServiceError {
let duration = Duration::from_millis(duration_ms as u64); let duration = Duration::from_millis(duration_ms as u64);
let is_periodic = false; let is_periodic = false;
unsafe {
let client_id = timer_get_sender_id(); let client_id = timer_get_sender_id();
match TIMER_SRV match TIMER_SRV
.lock() .lock()
@ -60,13 +57,14 @@ pub extern "C" fn timer_oneshot(timer_id: TimerId, duration_ms: u32) -> TimerSer
Ok(()) => TimerServiceError::TimerOk, Ok(()) => TimerServiceError::TimerOk,
} }
} }
}
#[no_mangle] #[no_mangle]
pub extern "C" fn timer_periodic(timer_id: TimerId, duration_ms: u32) -> TimerServiceError { pub unsafe extern "C" fn timer_periodic(
timer_id: TimerId,
duration_ms: u32
) -> TimerServiceError {
let duration = Duration::from_millis(duration_ms as u64); let duration = Duration::from_millis(duration_ms as u64);
let is_periodic = true; let is_periodic = true;
unsafe {
let client_id = timer_get_sender_id(); let client_id = timer_get_sender_id();
match TIMER_SRV match TIMER_SRV
.lock() .lock()
@ -76,26 +74,23 @@ pub extern "C" fn timer_periodic(timer_id: TimerId, duration_ms: u32) -> TimerSe
Ok(()) => TimerServiceError::TimerOk, Ok(()) => TimerServiceError::TimerOk,
} }
} }
}
#[no_mangle] #[no_mangle]
pub extern "C" fn timer_cancel(timer_id: TimerId) -> TimerServiceError { pub unsafe extern "C" fn timer_cancel(
unsafe { timer_id: TimerId
) -> TimerServiceError {
let client_id = timer_get_sender_id(); let client_id = timer_get_sender_id();
match TIMER_SRV.lock().cancel(client_id, timer_id) { match TIMER_SRV.lock().cancel(client_id, timer_id) {
Err(e) => e, Err(e) => e,
Ok(()) => TimerServiceError::TimerOk, Ok(()) => TimerServiceError::TimerOk,
} }
} }
}
#[no_mangle] #[no_mangle]
pub extern "C" fn timer_interrupt_handle() { pub unsafe extern "C" fn timer_interrupt_handle() {
extern "C" { extern "C" {
fn timer_interrupt_acknowledge() -> u32; fn timer_interrupt_acknowledge() -> u32;
} }
unsafe {
TIMER_SRV.lock().service_interrupt(); TIMER_SRV.lock().service_interrupt();
} assert!(timer_interrupt_acknowledge() == 0);
assert!(unsafe { timer_interrupt_acknowledge() == 0 });
} }

View File

@ -72,8 +72,7 @@ impl KataTimerService {
if self if self
.events .events
.iter() .iter()
.find(|(_, ev)| ev.client_id == client_id && ev.timer_id == timer_id) .any(|(_, ev)| ev.client_id == client_id && ev.timer_id == timer_id)
.is_some()
{ {
return Err(TimerServiceError::TimerAlreadyExists); return Err(TimerServiceError::TimerAlreadyExists);
} }