From 2e3034193e19726ae8f0e47adbd89e2f7a756a97 Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Fri, 4 Mar 2022 16:09:04 +0100 Subject: [PATCH] Address comments --- src/env/tock/mod.rs | 21 ++++++++++----------- src/main.rs | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/env/tock/mod.rs b/src/env/tock/mod.rs index 1facc85..a8decfd 100644 --- a/src/env/tock/mod.rs +++ b/src/env/tock/mod.rs @@ -27,19 +27,18 @@ pub struct TockEnv { impl TockEnv { /// Returns the unique instance of the Tock environment. /// - /// This function returns `Some` the first time it is called. Afterwards, it repeatedly returns - /// `None`. - pub fn new() -> Option { + /// # Panics + /// + /// - If called a second time. + pub fn new() -> Self { // Make sure the environment was not already taken. static TAKEN: AtomicBool = AtomicBool::new(false); - if TAKEN.fetch_or(true, Ordering::SeqCst) { - return None; - } - Some(TockEnv { + assert!(!TAKEN.fetch_or(true, Ordering::SeqCst)); + TockEnv { rng: TockRng256 {}, storage: false, upgrade_storage: false, - }) + } } } @@ -47,11 +46,11 @@ impl TockEnv { /// /// # Safety /// -/// It is probably technically memory-safe to hame multiple storage instances at the same time, but +/// It is probably technically memory-safe to have multiple storage instances at the same time, but /// for extra precaution we mark the function as unsafe. To ensure correct usage, this function /// should only be called if the previous storage instance was dropped. -// This function is exposed for example binaries testing the hardware. This could probably be -// cleaned up by having the persistent store return its storage. +// This function is exposed to example binaries testing the hardware. This could probably be cleaned +// up by having the persistent store return its storage. pub unsafe fn steal_storage() -> StorageResult { SyscallStorage::new() } diff --git a/src/main.rs b/src/main.rs index ab3be82..04f4c3b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,7 +57,7 @@ fn main() { } let boot_time = timer.get_current_clock().flex_unwrap(); - let env = TockEnv::new().unwrap(); + let env = TockEnv::new(); let mut ctap = ctap2::Ctap::new(env, boot_time); let mut led_counter = 0;