diff --git a/apps/system/components/DebugConsole/kata-debug-console/src/run.rs b/apps/system/components/DebugConsole/kata-debug-console/src/run.rs index 43cdd56..9c7f4ec 100644 --- a/apps/system/components/DebugConsole/kata-debug-console/src/run.rs +++ b/apps/system/components/DebugConsole/kata-debug-console/src/run.rs @@ -12,13 +12,10 @@ #![no_std] use core::slice; -use kata_io; use kata_os_common::allocator; use kata_os_common::logger::KataLogger; use kata_os_common::sel4_sys; use kata_os_common::slot_allocator; -use kata_shell; -use kata_uart_client; use log::trace; use sel4_sys::seL4_CPtr; diff --git a/apps/system/components/DebugConsole/kata-io/src/lib.rs b/apps/system/components/DebugConsole/kata-io/src/lib.rs index 68e73d3..3a74f97 100644 --- a/apps/system/components/DebugConsole/kata-io/src/lib.rs +++ b/apps/system/components/DebugConsole/kata-io/src/lib.rs @@ -127,7 +127,7 @@ impl BufReader { pub fn new(inner: R) -> BufReader { const BUFFER_SIZE : usize = 1024; // free to be changed BufReader { - inner: inner, + inner, buf: Box::new([0u8; BUFFER_SIZE]), pos: 0, cap: 0, diff --git a/apps/system/components/DebugConsole/kata-line-reader/src/lib.rs b/apps/system/components/DebugConsole/kata-line-reader/src/lib.rs index 5bce7e0..19bb949 100644 --- a/apps/system/components/DebugConsole/kata-line-reader/src/lib.rs +++ b/apps/system/components/DebugConsole/kata-line-reader/src/lib.rs @@ -38,6 +38,11 @@ pub struct LineReader { // Owned by LineReader to facilitate static allocation. buf: [u8; LINE_MAX], } +impl Default for LineReader { + fn default() -> Self { + Self::new() + } +} fn get_u8(reader: &mut dyn io::Read) -> io::Result { let mut buf: [u8; 1] = [0u8]; diff --git a/apps/system/components/DebugConsole/kata-shell/src/lib.rs b/apps/system/components/DebugConsole/kata-shell/src/lib.rs index 0acf35c..3de2a70 100644 --- a/apps/system/components/DebugConsole/kata-shell/src/lib.rs +++ b/apps/system/components/DebugConsole/kata-shell/src/lib.rs @@ -6,8 +6,6 @@ use alloc::vec::Vec; use core::fmt; use core::fmt::Write; use cpio::CpioNewcReader; -use hex; -use log; use kata_io as io; use kata_line_reader::LineReader; @@ -124,7 +122,7 @@ fn dispatch_command( builtin_cpio: &[u8], ) { let mut args = cmdline.split_ascii_whitespace(); - match args.nth(0) { + match args.next() { Some(command) => { // Statically binds command names to implementations fns, which are // defined below. @@ -221,7 +219,7 @@ fn loglevel_command( args: &mut dyn Iterator, output: &mut dyn io::Write, ) -> Result<(), CommandError> { - if let Some(level) = args.nth(0) { + if let Some(level) = args.next() { use log::LevelFilter; match level { "off" => log::set_max_level(LevelFilter::Off), @@ -652,7 +650,7 @@ fn test_mlcontinuous_command(args: &mut dyn Iterator) -> Result<(), extern "C" { fn mlcoord_set_continuous_mode(mode: bool); } - if let Some(mode_str) = args.nth(0) { + if let Some(mode_str) = args.next() { let mode = mode_str.parse::()?; unsafe { mlcoord_set_continuous_mode(mode); @@ -779,7 +777,7 @@ fn test_timer_async_command( timer_service_oneshot(id, time_ms); - return Ok(()); + Ok(()) } /// Implements a command that starts a timer, blocking until the timer has diff --git a/apps/system/components/DebugConsole/kata-shell/src/rz.rs b/apps/system/components/DebugConsole/kata-shell/src/rz.rs index 7f57f4b..8b1596e 100644 --- a/apps/system/components/DebugConsole/kata-shell/src/rz.rs +++ b/apps/system/components/DebugConsole/kata-shell/src/rz.rs @@ -10,7 +10,6 @@ use core::ptr; use kata_memory_interface::kata_frame_alloc; use kata_memory_interface::ObjDescBundle; use kata_os_common::sel4_sys; -use log; use sel4_sys::seL4_CapRights; use sel4_sys::seL4_CPtr; @@ -21,8 +20,6 @@ use sel4_sys::seL4_RISCV_Page_Map as seL4_Page_Map; use sel4_sys::seL4_RISCV_Page_Unmap as seL4_Page_Unmap; use sel4_sys::seL4_RISCV_VMAttributes::Default_VMAttributes as seL4_Default_VMAttributes; -use zmodem; - use kata_io as io; #[derive(Debug)] @@ -132,7 +129,7 @@ impl Drop for Upload { impl io::Write for Upload { fn write(&mut self, buf: &[u8]) -> io::Result { let mut cursor = buf; - while cursor.len() > 0 { + while !cursor.is_empty() { let available_bytes = self.mapped_bytes - self.next_free; if available_bytes > 0 { // Fill the current frame (as space permits). @@ -156,7 +153,7 @@ impl io::Write for Upload { self.unmap_current_frame()?; } } - if cursor.len() == 0 { break } + if cursor.is_empty() { break } // Allocate another frame and map it for write. self.expand_and_map()?; diff --git a/apps/system/components/DebugConsole/kata-uart-client/src/lib.rs b/apps/system/components/DebugConsole/kata-uart-client/src/lib.rs index 037cddf..a4fa951 100644 --- a/apps/system/components/DebugConsole/kata-uart-client/src/lib.rs +++ b/apps/system/components/DebugConsole/kata-uart-client/src/lib.rs @@ -6,7 +6,8 @@ use kata_io as io; // Console logging interface. #[no_mangle] -pub extern "C" fn logger_log(level: u8, msg: *const cstr_core::c_char) { +#[allow(clippy::missing_safety_doc)] +pub unsafe extern "C" fn logger_log(level: u8, msg: *const cstr_core::c_char) { use log::Level; let l = match level { x if x == Level::Error as u8 => Level::Error, @@ -18,9 +19,7 @@ pub extern "C" fn logger_log(level: u8, msg: *const cstr_core::c_char) { if l <= log::max_level() { // TODO(sleffler): is the uart driver ok w/ multiple writers? let output: &mut dyn io::Write = &mut self::Tx::new(); - unsafe { - let _ = writeln!(output, "{}", CStr::from_ptr(msg).to_str().unwrap()); - } + let _ = writeln!(output, "{}", CStr::from_ptr(msg).to_str().unwrap()); } } @@ -29,6 +28,11 @@ const DATAPORT_SIZE: usize = 4096; pub struct Rx { dataport: &'static [u8], } +impl Default for Rx { + fn default() -> Self { + Self::new() + } +} impl Rx { pub fn new() -> Rx { @@ -60,6 +64,11 @@ impl io::Read for Rx { pub struct Tx { dataport: &'static mut [u8], } +impl Default for Tx { + fn default() -> Self { + Self::new() + } +} impl Tx { pub fn new() -> Tx { diff --git a/apps/system/components/DebugConsole/zmodem/src/frame.rs b/apps/system/components/DebugConsole/zmodem/src/frame.rs index f8e6829..c2d139f 100644 --- a/apps/system/components/DebugConsole/zmodem/src/frame.rs +++ b/apps/system/components/DebugConsole/zmodem/src/frame.rs @@ -1,4 +1,5 @@ use alloc::string::String; +use alloc::vec; use alloc::vec::Vec; use core::fmt; @@ -46,9 +47,8 @@ impl Frame { } pub fn build(&self) -> Vec { - let mut out = Vec::new(); + let mut out = vec![ZPAD]; - out.push(ZPAD); if self.header == ZHEX { out.push(ZPAD); } @@ -63,7 +63,7 @@ impl Frame { if self.header == ZHEX { let hex = out.drain(4..).collect::>().encode_hex::(); - out.extend_from_slice(&hex.as_bytes()); + out.extend_from_slice(hex.as_bytes()); } let tmp = out.drain(3..).collect::>(); diff --git a/apps/system/components/DebugConsole/zmodem/src/proto.rs b/apps/system/components/DebugConsole/zmodem/src/proto.rs index 0c6da92..852ef25 100644 --- a/apps/system/components/DebugConsole/zmodem/src/proto.rs +++ b/apps/system/components/DebugConsole/zmodem/src/proto.rs @@ -1,5 +1,6 @@ use alloc::vec::Vec; use alloc::{format, vec}; +use alloc::string::ToString; use kata_io as io; use log::Level::Debug; @@ -35,7 +36,7 @@ where Ok(true) } -pub fn parse_header<'a, R>(mut r: R) -> io::Result> +pub fn parse_header(mut r: R) -> io::Result> where R: io::Read, { @@ -209,10 +210,7 @@ fn unescape(escaped_byte: u8) -> u8 { } fn is_escaped(byte: u8) -> bool { - match byte { - ZCRCE | ZCRCG | ZCRCQ | ZCRCW => false, - _ => true, - } + !matches!(byte, ZCRCE | ZCRCG | ZCRCQ | ZCRCW) } /// Reads out one byte @@ -254,7 +252,7 @@ where if let Some(size) = filesize { zfile_data += &format!(" {}", size); } - zfile_data += &format!("\0"); + zfile_data += &"\0".to_string(); debug!("ZFILE supplied data: {}", zfile_data); write_zlde_data(w, ZCRCW, zfile_data.as_bytes())