From 4bdb4c8e115a84203c8d978816cc1f2a45124b2f Mon Sep 17 00:00:00 2001 From: mwojcik Date: Thu, 19 May 2022 15:25:01 +0800 Subject: [PATCH] config: error instead of empty value if key not found --- artiq/firmware/libboard_misoc/config.rs | 7 ++++++- artiq/firmware/runtime/session.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/artiq/firmware/libboard_misoc/config.rs b/artiq/firmware/libboard_misoc/config.rs index 9a737e303..51f71ac33 100644 --- a/artiq/firmware/libboard_misoc/config.rs +++ b/artiq/firmware/libboard_misoc/config.rs @@ -9,6 +9,7 @@ pub enum Error { MissingSeparator { offset: usize }, Utf8Error(str::Utf8Error), NoFlash, + KeyNotFound } impl fmt::Display for Error { @@ -28,6 +29,8 @@ impl fmt::Display for Error { write!(f, "{}", err), &Error::NoFlash => write!(f, "flash memory is not present"), + &Error::KeyNotFound => + write!(f, "key not found") } } } @@ -156,14 +159,16 @@ mod imp { f(Lock::take().and_then(|lock| { let mut iter = Iter::new(lock.data()); let mut value = &[][..]; + let mut found = false; while let Some(result) = iter.next() { let (record_key, record_value) = result?; if key.as_bytes() == record_key { + found = true; // last write wins value = record_value } } - Ok(value) + if found { Ok(value) } else { Err(Error::KeyNotFound) } })) } diff --git a/artiq/firmware/runtime/session.rs b/artiq/firmware/runtime/session.rs index bd1562269..c6d745545 100644 --- a/artiq/firmware/runtime/session.rs +++ b/artiq/firmware/runtime/session.rs @@ -529,7 +529,7 @@ fn flash_kernel_worker(io: &Io, aux_mutex: &Mutex, config::read(config_key, |result| { match result { - Ok(kernel) if kernel.len() > 0 => unsafe { + Ok(kernel) => unsafe { // kernel CPU cannot access the SPI flash address space directly, // so make a copy. kern_load(io, &mut session, Vec::from(kernel).as_ref())