DebugConsole: clippy findings

Change-Id: I8e93e5441e5762171b4e32baa253ceba6d96855b
GitOrigin-RevId: 90106f4f236c27f88a59ea6286612bb6db378cfc
This commit is contained in:
Sam Leffler
2022-05-16 18:45:41 +00:00
parent c4563fabfb
commit b8dfe92451
8 changed files with 32 additions and 28 deletions

View File

@@ -12,13 +12,10 @@
#![no_std] #![no_std]
use core::slice; use core::slice;
use kata_io;
use kata_os_common::allocator; use kata_os_common::allocator;
use kata_os_common::logger::KataLogger; use kata_os_common::logger::KataLogger;
use kata_os_common::sel4_sys; use kata_os_common::sel4_sys;
use kata_os_common::slot_allocator; use kata_os_common::slot_allocator;
use kata_shell;
use kata_uart_client;
use log::trace; use log::trace;
use sel4_sys::seL4_CPtr; use sel4_sys::seL4_CPtr;

View File

@@ -127,7 +127,7 @@ impl<R: Read> BufReader<R> {
pub fn new(inner: R) -> BufReader<R> { pub fn new(inner: R) -> BufReader<R> {
const BUFFER_SIZE : usize = 1024; // free to be changed const BUFFER_SIZE : usize = 1024; // free to be changed
BufReader { BufReader {
inner: inner, inner,
buf: Box::new([0u8; BUFFER_SIZE]), buf: Box::new([0u8; BUFFER_SIZE]),
pos: 0, pos: 0,
cap: 0, cap: 0,

View File

@@ -38,6 +38,11 @@ pub struct LineReader {
// Owned by LineReader to facilitate static allocation. // Owned by LineReader to facilitate static allocation.
buf: [u8; LINE_MAX], buf: [u8; LINE_MAX],
} }
impl Default for LineReader {
fn default() -> Self {
Self::new()
}
}
fn get_u8(reader: &mut dyn io::Read) -> io::Result<u8> { fn get_u8(reader: &mut dyn io::Read) -> io::Result<u8> {
let mut buf: [u8; 1] = [0u8]; let mut buf: [u8; 1] = [0u8];

View File

@@ -6,8 +6,6 @@ use alloc::vec::Vec;
use core::fmt; use core::fmt;
use core::fmt::Write; use core::fmt::Write;
use cpio::CpioNewcReader; use cpio::CpioNewcReader;
use hex;
use log;
use kata_io as io; use kata_io as io;
use kata_line_reader::LineReader; use kata_line_reader::LineReader;
@@ -124,7 +122,7 @@ fn dispatch_command(
builtin_cpio: &[u8], builtin_cpio: &[u8],
) { ) {
let mut args = cmdline.split_ascii_whitespace(); let mut args = cmdline.split_ascii_whitespace();
match args.nth(0) { match args.next() {
Some(command) => { Some(command) => {
// Statically binds command names to implementations fns, which are // Statically binds command names to implementations fns, which are
// defined below. // defined below.
@@ -221,7 +219,7 @@ fn loglevel_command(
args: &mut dyn Iterator<Item = &str>, args: &mut dyn Iterator<Item = &str>,
output: &mut dyn io::Write, output: &mut dyn io::Write,
) -> Result<(), CommandError> { ) -> Result<(), CommandError> {
if let Some(level) = args.nth(0) { if let Some(level) = args.next() {
use log::LevelFilter; use log::LevelFilter;
match level { match level {
"off" => log::set_max_level(LevelFilter::Off), "off" => log::set_max_level(LevelFilter::Off),
@@ -652,7 +650,7 @@ fn test_mlcontinuous_command(args: &mut dyn Iterator<Item = &str>) -> Result<(),
extern "C" { extern "C" {
fn mlcoord_set_continuous_mode(mode: bool); 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::<bool>()?; let mode = mode_str.parse::<bool>()?;
unsafe { unsafe {
mlcoord_set_continuous_mode(mode); mlcoord_set_continuous_mode(mode);
@@ -779,7 +777,7 @@ fn test_timer_async_command(
timer_service_oneshot(id, time_ms); timer_service_oneshot(id, time_ms);
return Ok(()); Ok(())
} }
/// Implements a command that starts a timer, blocking until the timer has /// Implements a command that starts a timer, blocking until the timer has

View File

@@ -10,7 +10,6 @@ use core::ptr;
use kata_memory_interface::kata_frame_alloc; use kata_memory_interface::kata_frame_alloc;
use kata_memory_interface::ObjDescBundle; use kata_memory_interface::ObjDescBundle;
use kata_os_common::sel4_sys; use kata_os_common::sel4_sys;
use log;
use sel4_sys::seL4_CapRights; use sel4_sys::seL4_CapRights;
use sel4_sys::seL4_CPtr; 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_Page_Unmap as seL4_Page_Unmap;
use sel4_sys::seL4_RISCV_VMAttributes::Default_VMAttributes as seL4_Default_VMAttributes; use sel4_sys::seL4_RISCV_VMAttributes::Default_VMAttributes as seL4_Default_VMAttributes;
use zmodem;
use kata_io as io; use kata_io as io;
#[derive(Debug)] #[derive(Debug)]
@@ -132,7 +129,7 @@ impl Drop for Upload {
impl io::Write for Upload { impl io::Write for Upload {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
let mut cursor = buf; let mut cursor = buf;
while cursor.len() > 0 { while !cursor.is_empty() {
let available_bytes = self.mapped_bytes - self.next_free; let available_bytes = self.mapped_bytes - self.next_free;
if available_bytes > 0 { if available_bytes > 0 {
// Fill the current frame (as space permits). // Fill the current frame (as space permits).
@@ -156,7 +153,7 @@ impl io::Write for Upload {
self.unmap_current_frame()?; self.unmap_current_frame()?;
} }
} }
if cursor.len() == 0 { break } if cursor.is_empty() { break }
// Allocate another frame and map it for write. // Allocate another frame and map it for write.
self.expand_and_map()?; self.expand_and_map()?;

View File

@@ -6,7 +6,8 @@ use kata_io as io;
// Console logging interface. // Console logging interface.
#[no_mangle] #[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; use log::Level;
let l = match level { let l = match level {
x if x == Level::Error as u8 => Level::Error, 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() { if l <= log::max_level() {
// TODO(sleffler): is the uart driver ok w/ multiple writers? // TODO(sleffler): is the uart driver ok w/ multiple writers?
let output: &mut dyn io::Write = &mut self::Tx::new(); 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 { pub struct Rx {
dataport: &'static [u8], dataport: &'static [u8],
} }
impl Default for Rx {
fn default() -> Self {
Self::new()
}
}
impl Rx { impl Rx {
pub fn new() -> Rx { pub fn new() -> Rx {
@@ -60,6 +64,11 @@ impl io::Read for Rx {
pub struct Tx { pub struct Tx {
dataport: &'static mut [u8], dataport: &'static mut [u8],
} }
impl Default for Tx {
fn default() -> Self {
Self::new()
}
}
impl Tx { impl Tx {
pub fn new() -> Tx { pub fn new() -> Tx {

View File

@@ -1,4 +1,5 @@
use alloc::string::String; use alloc::string::String;
use alloc::vec;
use alloc::vec::Vec; use alloc::vec::Vec;
use core::fmt; use core::fmt;
@@ -46,9 +47,8 @@ impl Frame {
} }
pub fn build(&self) -> Vec<u8> { pub fn build(&self) -> Vec<u8> {
let mut out = Vec::new(); let mut out = vec![ZPAD];
out.push(ZPAD);
if self.header == ZHEX { if self.header == ZHEX {
out.push(ZPAD); out.push(ZPAD);
} }
@@ -63,7 +63,7 @@ impl Frame {
if self.header == ZHEX { if self.header == ZHEX {
let hex = out.drain(4..).collect::<Vec<u8>>().encode_hex::<String>(); let hex = out.drain(4..).collect::<Vec<u8>>().encode_hex::<String>();
out.extend_from_slice(&hex.as_bytes()); out.extend_from_slice(hex.as_bytes());
} }
let tmp = out.drain(3..).collect::<Vec<_>>(); let tmp = out.drain(3..).collect::<Vec<_>>();

View File

@@ -1,5 +1,6 @@
use alloc::vec::Vec; use alloc::vec::Vec;
use alloc::{format, vec}; use alloc::{format, vec};
use alloc::string::ToString;
use kata_io as io; use kata_io as io;
use log::Level::Debug; use log::Level::Debug;
@@ -35,7 +36,7 @@ where
Ok(true) Ok(true)
} }
pub fn parse_header<'a, R>(mut r: R) -> io::Result<Option<Frame>> pub fn parse_header<R>(mut r: R) -> io::Result<Option<Frame>>
where where
R: io::Read, R: io::Read,
{ {
@@ -209,10 +210,7 @@ fn unescape(escaped_byte: u8) -> u8 {
} }
fn is_escaped(byte: u8) -> bool { fn is_escaped(byte: u8) -> bool {
match byte { !matches!(byte, ZCRCE | ZCRCG | ZCRCQ | ZCRCW)
ZCRCE | ZCRCG | ZCRCQ | ZCRCW => false,
_ => true,
}
} }
/// Reads out one byte /// Reads out one byte
@@ -254,7 +252,7 @@ where
if let Some(size) = filesize { if let Some(size) = filesize {
zfile_data += &format!(" {}", size); zfile_data += &format!(" {}", size);
} }
zfile_data += &format!("\0"); zfile_data += &"\0".to_string();
debug!("ZFILE supplied data: {}", zfile_data); debug!("ZFILE supplied data: {}", zfile_data);
write_zlde_data(w, ZCRCW, zfile_data.as_bytes()) write_zlde_data(w, ZCRCW, zfile_data.as_bytes())