Fix or silence clippy warnings on nightly

Fix:
- dead_code
- clippy::if_then_panic
- clippy::manual_memcpy
- clippy::needless_borrow

Silence:
- clippy::missing_safety_doc
- clippy::needless_range_loop
- clippy::single_match

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2021-10-22 16:30:32 -06:00
committed by Jeremy Soller
parent 975377af42
commit 43e5cf4ba3
6 changed files with 13 additions and 16 deletions

View File

@ -40,9 +40,7 @@ impl AccessHid {
}
hid_data[HID_CMD] = cmd;
for i in 0..data.len() {
hid_data[HID_DATA + i] = data[i];
}
hid_data[HID_DATA..(data.len() + HID_DATA)].clone_from_slice(data);
let count = self.device.write(&hid_data)?;
if count != hid_data.len() {
@ -51,9 +49,7 @@ impl AccessHid {
let count = self.device.read_timeout(&mut hid_data[1..], self.timeout)?;
if count == hid_data.len() - 1 {
for i in 0..data.len() {
data[i] = hid_data[HID_DATA + i];
}
data.clone_from_slice(&hid_data[HID_DATA..(data.len() + HID_DATA)]);
Ok(Some(hid_data[HID_RES]))
} else if count == 0 {

View File

@ -4,6 +4,7 @@ const SMFI_CMD_BASE: u16 = 0xE00;
const SMFI_CMD_SIZE: usize = 0x100;
const SMFI_DBG_BASE: u16 = 0xF00;
#[cfg(all(feature = "std", target_os = "linux"))]
const SMFI_DBG_SIZE: usize = 0x100;
const SMFI_CMD_CMD: u8 = 0x00;

View File

@ -128,9 +128,7 @@ impl<A: Access> Ec<A> {
let mut data = [0; 256 - 2];
data[0] = flags;
data[1] = chunk.len() as u8;
for i in 0..chunk.len() {
data[i + 2] = chunk[i];
}
data[2..chunk.len()].clone_from_slice(chunk);
self.command(Cmd::Print, &mut data)?;
if data[1] != chunk.len() as u8 {
return Err(Error::Verify);

View File

@ -14,6 +14,9 @@
//! compiler. It is only recommended to use these in firmware, as mutual exclusion is not
//! guaranteed.
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::needless_range_loop)]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(not(feature = "std"))]

View File

@ -155,9 +155,7 @@ unsafe fn flash(ec: &mut Ec<Box<dyn Access>>, path: &str, target: SpiTarget) ->
let ec_board = &data[..size];
println!("ec board: {:?}", str::from_utf8(ec_board));
if ec_board != firmware.board {
panic!("file board does not match ec board");
}
assert!(ec_board == firmware.board, "file board does not match ec board");
}
{
@ -395,6 +393,7 @@ fn main() {
"hid" => {
let api = HidApi::new()?;
for info in api.device_list() {
#[allow(clippy::single_match)]
match (info.vendor_id(), info.product_id(), info.interface_number()) {
// System76 launch_1
(0x3384, 0x0001, 1) => {
@ -449,7 +448,7 @@ fn main() {
},
("flash", Some(sub_m)) => {
let path = sub_m.value_of("path").unwrap();
match unsafe { flash(&mut ec, &path, SpiTarget::Main) } {
match unsafe { flash(&mut ec, path, SpiTarget::Main) } {
Ok(()) => (),
Err(err) => {
eprintln!("failed to flash '{}': {:X?}", path, err);
@ -459,7 +458,7 @@ fn main() {
},
("flash_backup", Some(sub_m)) => {
let path = sub_m.value_of("path").unwrap();
match unsafe { flash(&mut ec, &path, SpiTarget::Backup) } {
match unsafe { flash(&mut ec, path, SpiTarget::Backup) } {
Ok(()) => (),
Err(err) => {
eprintln!("failed to flash '{}': {:X?}", path, err);
@ -589,7 +588,7 @@ fn main() {
("print", Some(sub_m)) => for arg in sub_m.values_of("message").unwrap() {
let mut arg = arg.to_owned();
arg.push('\n');
match unsafe { print(&mut ec, &arg.as_bytes()) } {
match unsafe { print(&mut ec, arg.as_bytes()) } {
Ok(()) => (),
Err(err) => {
eprintln!("failed to print '{}': {:X?}", arg, err);

View File

@ -196,7 +196,7 @@ impl<'a, S: Spi, T: Timeout> SpiRom<'a, S, T> {
(page_address >> 8) as u8,
page_address as u8,
])?;
self.spi.write(&page)?;
self.spi.write(page)?;
// Poll status for busy unset
self.status_wait(1, 0)?;