From bd53b2cbaa2ece304531d048dcbb857cdfb574d3 Mon Sep 17 00:00:00 2001 From: Laura Abbott Date: Fri, 15 Sep 2023 10:57:29 -0400 Subject: [PATCH] Clippy Fixes Also add clippy to the build process --- .github/workflows/build-one.yml | 9 ++- app/oxcon2023g0/src/main.rs | 1 + build/i2c/src/lib.rs | 3 + build/lpc55pins/src/lib.rs | 2 +- build/xtask/src/clippy.rs | 12 +++- drv/fpga-devices/src/ecp5_spi.rs | 27 ++++++--- drv/gimlet-hf-server/src/main.rs | 2 +- drv/i2c-devices/src/ltc4282.rs | 1 + drv/lpc55-spi/src/lib.rs | 4 +- drv/lpc55-sprot-server/src/handler.rs | 14 ++--- drv/lpc55-sprot-server/src/main.rs | 8 ++- drv/lpc55-swd/build.rs | 6 +- drv/lpc55-swd/src/main.rs | 6 +- drv/lpc55-update-server/src/main.rs | 26 ++++----- drv/oxide-vpd/src/lib.rs | 8 +-- drv/sprot-api/src/error.rs | 16 ++++-- drv/sprot-api/src/lib.rs | 11 ++-- drv/stm32fx-usart/src/main.rs | 4 +- drv/stm32h7-spi-server-core/build.rs | 18 ++---- drv/stm32h7-sprot-server/src/main.rs | 40 ++++++------- drv/stm32h7-update-server/src/main.rs | 3 +- drv/stm32xx-i2c-server/src/main.rs | 16 +++--- drv/transceivers-server/src/main.rs | 2 + lib/dice/src/mfg.rs | 6 +- lib/lpc55-puf/src/lib.rs | 5 +- lib/lpc55-rot-startup/build.rs | 2 +- lib/lpc55-rot-startup/src/dice.rs | 34 ++++++----- lib/lpc55-rot-startup/src/dice_mfg_usart.rs | 13 +++-- lib/lpc55-rot-startup/src/images.rs | 22 +++---- lib/lpc55-rot-startup/src/lib.rs | 8 +-- lib/task-config/src/lib.rs | 63 +++++++++++---------- sys/kern/build.rs | 4 +- sys/kern/src/arch/arm_m.rs | 6 +- sys/kern/src/fail.rs | 2 +- sys/kern/src/kipc.rs | 2 +- task/control-plane-agent/src/mgs_common.rs | 8 +-- task/dump-agent/src/main.rs | 14 +++-- task/dumper/src/main.rs | 12 ++-- task/hiffy/src/stm32g0.rs | 4 +- task/host-sp-comms/src/bsp/gimlet_bcde.rs | 18 +++--- task/jefe/build.rs | 4 +- task/jefe/src/dump.rs | 6 +- task/jefe/src/main.rs | 41 +++++++------- task/net/build.rs | 2 +- task/net/src/server.rs | 1 + task/packrat/build.rs | 15 +++-- task/packrat/src/main.rs | 4 +- task/power/src/main.rs | 2 +- task/sensor/src/main.rs | 2 +- task/sp_measure/build.rs | 2 +- task/sp_measure/src/main.rs | 2 +- task/thermal/src/control.rs | 6 +- task/uartecho/src/main.rs | 25 +++----- task/udpbroadcast/src/main.rs | 2 +- 54 files changed, 298 insertions(+), 278 deletions(-) diff --git a/.github/workflows/build-one.yml b/.github/workflows/build-one.yml index 5e489c87c..408697404 100644 --- a/.github/workflows/build-one.yml +++ b/.github/workflows/build-one.yml @@ -40,7 +40,9 @@ jobs: # install rust toolchain - name: Install Rust toolchain - run: rustup show + run: | + rustup show + rustup component add clippy - name: Cache build output uses: Swatinem/rust-cache@v2 @@ -81,6 +83,11 @@ jobs: target/release/humility -a target/${{ inputs.app_name }}/dist/build-${{ inputs.app_name }}-image-$image.zip manifest; \ done + - name: Clippy + if: inputs.os == 'ubuntu-latest' + run: | + cargo xtask clippy ${{ inputs.app_toml}} -- --deny warnings + # upload the output of our build - name: Upload build archive uses: actions/upload-artifact@v3 diff --git a/app/oxcon2023g0/src/main.rs b/app/oxcon2023g0/src/main.rs index d59989ab6..3fd879f63 100644 --- a/app/oxcon2023g0/src/main.rs +++ b/app/oxcon2023g0/src/main.rs @@ -34,6 +34,7 @@ fn main() -> ! { rcc.pllsyscfgr.write(|w| { unsafe { w.pllsrc().bits(0b10); // HSI16, I promise + #[allow(clippy::eq_op)] w.pllm().bits(1 - 1); w.plln().bits(8); // _not_ an n-1 field w.pllr().bits(2 - 1); diff --git a/build/i2c/src/lib.rs b/build/i2c/src/lib.rs index ed601b244..e1f52ff25 100644 --- a/build/i2c/src/lib.rs +++ b/build/i2c/src/lib.rs @@ -1008,6 +1008,7 @@ impl ConfigGenerator { &mut self.output, r##" #[allow(dead_code)] + #[allow(clippy::match_single_binding)] pub fn lookup_controller(index: usize) -> Option {{ match index {{"## )?; @@ -1038,6 +1039,7 @@ impl ConfigGenerator { &mut self.output, r##" #[allow(dead_code)] + #[allow(clippy::match_single_binding)] pub fn lookup_port(index: usize) -> Option {{ match index {{"## )?; @@ -1219,6 +1221,7 @@ impl ConfigGenerator { }} #[allow(unused_variables)] + #[allow(clippy::match_single_binding)] pub fn validate( task: TaskId, index: usize, diff --git a/build/lpc55pins/src/lib.rs b/build/lpc55pins/src/lib.rs index aabdfb945..d0e6e8d70 100644 --- a/build/lpc55pins/src/lib.rs +++ b/build/lpc55pins/src/lib.rs @@ -119,7 +119,7 @@ impl ToTokens for PinConfig { pub fn codegen(pins: Vec) -> Result<()> { let out_dir = build_util::out_dir(); let dest_path = out_dir.join("pin_config.rs"); - let mut file = std::fs::File::create(&dest_path)?; + let mut file = std::fs::File::create(dest_path)?; let mut buf = BufWriter::new(Vec::new()); if pins.iter().any(|p| p.name.is_some()) { diff --git a/build/xtask/src/clippy.rs b/build/xtask/src/clippy.rs index a6ea87a0d..cea586776 100644 --- a/build/xtask/src/clippy.rs +++ b/build/xtask/src/clippy.rs @@ -68,12 +68,15 @@ pub fn run( .ok_or_else(|| anyhow::anyhow!("Failed to get image name"))?; // Pick dummy entry points for each task - let entry_points = allocs + let mut entry_points: std::collections::HashMap<_, _> = allocs .tasks .iter() .map(|(k, v)| (k.clone(), v["flash"].start)) .collect(); + // add a dummy caboose point + entry_points.insert("caboose".to_string(), 0x0); + let kconfig = crate::dist::make_kconfig( &toml, &allocs.tasks, @@ -82,11 +85,18 @@ pub fn run( )?; let kconfig = ron::ser::to_string(&kconfig)?; + let flash_outputs = if let Some(o) = toml.outputs.get("flash") { + ron::ser::to_string(o)? + } else { + bail!("no 'flash' output regions defined in config toml"); + }; + toml.kernel_build_config( verbose, &[ ("HUBRIS_KCONFIG", &kconfig), ("HUBRIS_IMAGE_ID", "1234"), // dummy image ID + ("HUBRIS_FLASH_OUTPUTS", &flash_outputs), ], None, ) diff --git a/drv/fpga-devices/src/ecp5_spi.rs b/drv/fpga-devices/src/ecp5_spi.rs index 84a091f7f..2d768e722 100644 --- a/drv/fpga-devices/src/ecp5_spi.rs +++ b/drv/fpga-devices/src/ecp5_spi.rs @@ -62,7 +62,8 @@ impl Ecp5Driver for Ecp5UsingSpi { } fn set_program_n(&self, asserted: bool) -> Result<(), Self::Error> { - Ok(self.sys.gpio_set_to(self.program_n, asserted)) + self.sys.gpio_set_to(self.program_n, asserted); + Ok(()) } fn init_n(&self) -> Result { @@ -70,7 +71,8 @@ impl Ecp5Driver for Ecp5UsingSpi { } fn set_init_n(&self, asserted: bool) -> Result<(), Self::Error> { - Ok(self.sys.gpio_set_to(self.init_n, !asserted)) + self.sys.gpio_set_to(self.init_n, !asserted); + Ok(()) } fn done(&self) -> Result { @@ -78,7 +80,8 @@ impl Ecp5Driver for Ecp5UsingSpi { } fn set_done(&self, asserted: bool) -> Result<(), Self::Error> { - Ok(self.sys.gpio_set_to(self.done, asserted)) + self.sys.gpio_set_to(self.done, asserted); + Ok(()) } fn user_design_reset_n(&self) -> Result { @@ -89,7 +92,8 @@ impl Ecp5Driver for Ecp5UsingSpi { &self, asserted: bool, ) -> Result<(), Self::Error> { - Ok(self.sys.gpio_set_to(self.user_design_reset_n, asserted)) + self.sys.gpio_set_to(self.user_design_reset_n, asserted); + Ok(()) } fn user_design_reset_duration(&self) -> u64 { @@ -97,11 +101,13 @@ impl Ecp5Driver for Ecp5UsingSpi { } fn configuration_read(&self, data: &mut [u8]) -> Result<(), Self::Error> { - Ok(self.configuration_port.read(data)?) + self.configuration_port.read(data)?; + Ok(()) } fn configuration_write(&self, data: &[u8]) -> Result<(), Self::Error> { - Ok(self.configuration_port.write(data)?) + self.configuration_port.write(data)?; + Ok(()) } fn configuration_write_command( @@ -109,15 +115,18 @@ impl Ecp5Driver for Ecp5UsingSpi { c: Command, ) -> Result<(), Self::Error> { let buffer: [u8; 4] = [c as u8, 0, 0, 0]; - Ok(self.configuration_port.write(&buffer)?) + self.configuration_port.write(&buffer)?; + Ok(()) } fn configuration_lock(&self) -> Result<(), Self::Error> { - Ok(self.configuration_port.lock(spi_api::CsState::Asserted)?) + self.configuration_port.lock(spi_api::CsState::Asserted)?; + Ok(()) } fn configuration_release(&self) -> Result<(), Self::Error> { - Ok(self.configuration_port.release()?) + self.configuration_port.release()?; + Ok(()) } } diff --git a/drv/gimlet-hf-server/src/main.rs b/drv/gimlet-hf-server/src/main.rs index 0a2dea06d..20ec447f4 100644 --- a/drv/gimlet-hf-server/src/main.rs +++ b/drv/gimlet-hf-server/src/main.rs @@ -400,7 +400,7 @@ impl ServerImpl { if addr as usize / SECTOR_SIZE_BYTES == 0 && !matches!(protect, HfProtectMode::AllowModificationsToSector0) { - return Err(HfError::Sector0IsReserved.into()); + return Err(HfError::Sector0IsReserved); } self.check_muxed_to_sp()?; self.set_and_check_write_enable()?; diff --git a/drv/i2c-devices/src/ltc4282.rs b/drv/i2c-devices/src/ltc4282.rs index 1f2da2e43..573f21799 100644 --- a/drv/i2c-devices/src/ltc4282.rs +++ b/drv/i2c-devices/src/ltc4282.rs @@ -264,6 +264,7 @@ impl Validate for Ltc4282 { // naturally need to change.) We deliberately do not depend on the // mode settings because these can be strapped to different values. // + #[allow(clippy::bool_comparison)] Ok(control.on_fault_mask() == true && control.on_delay() == false && control.on_enb() == true diff --git a/drv/lpc55-spi/src/lib.rs b/drv/lpc55-spi/src/lib.rs index 65280592d..96250e660 100644 --- a/drv/lpc55-spi/src/lib.rs +++ b/drv/lpc55-spi/src/lib.rs @@ -338,11 +338,11 @@ impl Spi { /// /// Mixing and matching different frame sizes is not recommended. pub fn read_u16(&mut self) -> u16 { - self.reg.fiford.read().rxdata().bits() as u16 + self.reg.fiford.read().rxdata().bits() } pub fn read_u16_with_sot(&self) -> (u16, bool) { let reader = self.reg.fiford.read(); - (reader.rxdata().bits() as u16, reader.sot().bit_is_set()) + (reader.rxdata().bits(), reader.sot().bit_is_set()) } } diff --git a/drv/lpc55-sprot-server/src/handler.rs b/drv/lpc55-sprot-server/src/handler.rs index eb17aceeb..d76968e44 100644 --- a/drv/lpc55-sprot-server/src/handler.rs +++ b/drv/lpc55-sprot-server/src/handler.rs @@ -111,7 +111,7 @@ impl Handler { size: blob_size, }) => { let blob_size: usize = blob_size.try_into().unwrap_lite(); - if blob_size as usize > drv_sprot_api::MAX_BLOB_SIZE { + if blob_size > drv_sprot_api::MAX_BLOB_SIZE { // If there isn't enough room, then pack an error instead Response::pack( &Err(SprotError::Protocol( @@ -125,9 +125,9 @@ impl Handler { .read_raw_caboose( slot, start, - &mut buf[..blob_size as usize], + &mut buf[..blob_size], ) - .map_err(|e| RspBody::Caboose(Err(e.into())))?; + .map_err(|e| RspBody::Caboose(Err(e)))?; Ok(blob_size) }) { Ok(size) => size, @@ -182,7 +182,7 @@ impl Handler { pub fn handle_request( &mut self, - req: Request, + req: Request<'_>, stats: &mut RotIoStats, ) -> Result<(RspBody, Option), SprotError> { match req.body { @@ -195,7 +195,7 @@ impl Handler { }; Ok((RspBody::Status(status), None)) } - ReqBody::IoStats => Ok((RspBody::IoStats(stats.clone()), None)), + ReqBody::IoStats => Ok((RspBody::IoStats(*stats), None)), ReqBody::RotState => match self.update.status() { Ok(state) => { let msg = RotState::V1 { @@ -240,7 +240,7 @@ impl Handler { Ok((RspBody::Ok, None)) } ReqBody::Update(UpdateReq::WriteBlock { block_num }) => { - self.update.write_one_block(block_num as usize, &req.blob)?; + self.update.write_one_block(block_num as usize, req.blob)?; Ok((RspBody::Ok, None)) } ReqBody::Update(UpdateReq::Abort) => { @@ -266,7 +266,7 @@ impl Handler { CabooseReq::Size { slot } => { let rsp = match self.update.caboose_size(slot) { Ok(v) => Ok(CabooseRsp::Size(v)), - Err(e) => Err(e.into()), + Err(e) => Err(e), }; Ok((RspBody::Caboose(rsp), None)) } diff --git a/drv/lpc55-sprot-server/src/main.rs b/drv/lpc55-sprot-server/src/main.rs index 7eb77f95f..e3a623bb1 100644 --- a/drv/lpc55-sprot-server/src/main.rs +++ b/drv/lpc55-sprot-server/src/main.rs @@ -283,8 +283,12 @@ impl Io { } let upper = (read >> 8) as u8; let lower = read as u8; - rx.next().map(|b| *b = upper); - rx.next().map(|b| *b = lower); + if let Some(b) = rx.next() { + *b = upper; + } + if let Some(b) = rx.next() { + *b = lower; + } } Ok(()) }; diff --git a/drv/lpc55-swd/build.rs b/drv/lpc55-swd/build.rs index ff5ad1879..3c3ec6e5b 100644 --- a/drv/lpc55-swd/build.rs +++ b/drv/lpc55-swd/build.rs @@ -19,7 +19,7 @@ struct TaskConfig { fn generate_swd_functions(config: &TaskConfig) -> Result<()> { let out_dir = build_util::out_dir(); let dest_path = out_dir.join("swd.rs"); - let mut file = std::fs::File::create(&dest_path)?; + let mut file = std::fs::File::create(dest_path)?; let out_cfg = &config.out_cfg; let in_cfg = &config.in_cfg; @@ -53,7 +53,7 @@ fn generate_swd_functions(config: &TaskConfig) -> Result<()> { use drv_lpc55_gpio_api::*; let (pin, conf) = drv_lpc55_gpio_api::Pins::iocon_conf_val(#out_cfg); - let base = iocon_base + 4 * (pin as u32); + let base = iocon_base + 4 * pin; unsafe { core::ptr::write_volatile(base as *mut u32, conf); } @@ -67,7 +67,7 @@ fn generate_swd_functions(config: &TaskConfig) -> Result<()> { { use drv_lpc55_gpio_api::*; let (pin, conf) = drv_lpc55_gpio_api::Pins::iocon_conf_val(#in_cfg); - let base = iocon_base + 4 * (pin as u32); + let base = iocon_base + 4 * pin; unsafe { core::ptr::write_volatile(base as *mut u32, conf); } diff --git a/drv/lpc55-swd/src/main.rs b/drv/lpc55-swd/src/main.rs index 943398666..29ecc6ca5 100644 --- a/drv/lpc55-swd/src/main.rs +++ b/drv/lpc55-swd/src/main.rs @@ -456,10 +456,10 @@ impl idl::InOrderSpCtrlImpl for ServerImpl { // S0-S31 | 0b1000000..=0b1011111 => Ok::(register), - _ => Err(SpCtrlError::InvalidCoreRegister.into()) + _ => Err(SpCtrlError::InvalidCoreRegister) }?; - if let Err(_) = self.write_single_target_addr(DCRSR, r as u32) { + if self.write_single_target_addr(DCRSR, r as u32).is_err() { return Err(SpCtrlError::Fault.into()); } @@ -674,7 +674,7 @@ impl ServerImpl { } fn write_word(&mut self, val: u32) { - let parity: u32 = if val.count_ones() % 2 == 0 { 0 } else { 1 }; + let parity: u32 = u32::from(val.count_ones() % 2 != 0); let rev = val.reverse_bits(); diff --git a/drv/lpc55-update-server/src/main.rs b/drv/lpc55-update-server/src/main.rs index 242a1d3eb..335950163 100644 --- a/drv/lpc55-update-server/src/main.rs +++ b/drv/lpc55-update-server/src/main.rs @@ -337,7 +337,7 @@ impl idl::InOrderUpdateImpl for ServerImpl<'_> { // Read current CFPA contents. let mut cfpa = [[0u32; 4]; 512 / 16]; indirect_flash_read_words( - &mut self.flash, + &self.flash, cfpa_word_number, &mut cfpa, )?; @@ -351,7 +351,7 @@ impl idl::InOrderUpdateImpl for ServerImpl<'_> { // reserved. let offset = BOOT_PREFERENCE_FLASH_WORD_OFFSET as usize; let bit = cfpa[offset][0] & 1; - let new_bit = if slot == SlotId::A { 0 } else { 1 }; + let new_bit = u32::from(slot != SlotId::A); if bit == new_bit { // No need to write the CFPA if it's unchanged return Ok(()); @@ -411,7 +411,7 @@ impl idl::InOrderUpdateImpl for ServerImpl<'_> { self.flash .write_page( CFPA_SCRATCH_FLASH_ADDR, - &cfpa_bytes, + cfpa_bytes, wait_for_flash_interrupt, ) .map_err(|_| UpdateError::FlashError)?; @@ -477,12 +477,12 @@ impl ServerImpl<'_> { let mut pong_header = [0u32; 4]; indirect_flash_read_words( - &mut self.flash, + &self.flash, CFPA_PING_FLASH_WORD, core::slice::from_mut(&mut ping_header), )?; indirect_flash_read_words( - &mut self.flash, + &self.flash, CFPA_PONG_FLASH_WORD, core::slice::from_mut(&mut pong_header), )?; @@ -509,7 +509,7 @@ impl ServerImpl<'_> { cfpa_word_number + BOOT_PREFERENCE_FLASH_WORD_OFFSET; let mut boot_selection_word = [0u32; 4]; indirect_flash_read_words( - &mut self.flash, + &self.flash, boot_selection_word_number, core::slice::from_mut(&mut boot_selection_word), )?; @@ -521,7 +521,7 @@ impl ServerImpl<'_> { // Read the scratch boot version, which may be erased let mut scratch_header = [0u32; 4]; let scratch_header = match indirect_flash_read_words( - &mut self.flash, + &self.flash, CFPA_SCRATCH_FLASH_WORD, core::slice::from_mut(&mut scratch_header), ) { @@ -539,7 +539,7 @@ impl ServerImpl<'_> { CFPA_SCRATCH_FLASH_WORD + BOOT_PREFERENCE_FLASH_WORD_OFFSET; let mut scratch_boot_selection_word = [0u32; 4]; indirect_flash_read_words( - &mut self.flash, + &self.flash, scratch_boot_selection_word_number, core::slice::from_mut(&mut scratch_boot_selection_word), )?; @@ -650,7 +650,7 @@ fn indirect_flash_read( mut addr: u32, mut output: &mut [u8], ) -> Result<(), UpdateError> { - while output.len() > 0 { + while !output.is_empty() { // Convert from memory (byte) address to word address, per comments in // `lpc55_flash` driver. let word = (addr / 16) & ((1 << 18) - 1); @@ -854,7 +854,7 @@ fn caboose_slice( ) .map_err(|_| RawCabooseError::ReadFailed)?; if header.magic != HEADER_MAGIC { - return Err(RawCabooseError::NoImageHeader.into()); + return Err(RawCabooseError::NoImageHeader); } // Calculate where the image header implies that the image should end @@ -866,7 +866,7 @@ fn caboose_slice( // // SAFETY: populated by the linker, so this should be valid if image_end > image_region_end { - return Err(RawCabooseError::MissingCaboose.into()); + return Err(RawCabooseError::MissingCaboose); } // By construction, the last word of the caboose is its size as a `u32` @@ -879,7 +879,7 @@ fn caboose_slice( // This branch will be encountered if there's no caboose, because // then the nominal caboose size will be 0xFFFFFFFF, which will send // us out of the bank2 region. - return Err(RawCabooseError::MissingCaboose.into()); + return Err(RawCabooseError::MissingCaboose); } else { // SAFETY: we know this pointer is within the programmed flash region, // since it's checked above. @@ -889,7 +889,7 @@ fn caboose_slice( if v == CABOOSE_MAGIC { caboose_start + 4..image_end - 4 } else { - return Err(RawCabooseError::MissingCaboose.into()); + return Err(RawCabooseError::MissingCaboose); } }; Ok(caboose_range) diff --git a/drv/oxide-vpd/src/lib.rs b/drv/oxide-vpd/src/lib.rs index ba8376fd0..f28a2e7a1 100644 --- a/drv/oxide-vpd/src/lib.rs +++ b/drv/oxide-vpd/src/lib.rs @@ -185,17 +185,17 @@ fn read_config_inner( chunk .read_exact(0, &mut out[..chunk_len]) .map_err(VpdError::ErrorOnRead)?; - return Ok(chunk_len); + Ok(chunk_len) } /// Searches for a single tag, which may appear multiple times /// /// Returns the `index`'th chunk with a matching tag. -fn get_chunk_for_tag<'a, 'b>( - mut reader: TlvcReader>, +fn get_chunk_for_tag( + mut reader: TlvcReader>, tag: [u8; 4], index: usize, -) -> Result>, VpdError> { +) -> Result>, VpdError> { let mut count = 0; loop { match reader.next() { diff --git a/drv/sprot-api/src/error.rs b/drv/sprot-api/src/error.rs index 677e286e8..fe7803c95 100644 --- a/drv/sprot-api/src/error.rs +++ b/drv/sprot-api/src/error.rs @@ -142,11 +142,15 @@ impl SprotError { match *self { SprotError::Protocol(err) => { use SprotProtocolError::*; - match err { - InvalidCrc | FlowError | Timeout | TaskRestarted - | Deserialization | Desynchronized => true, - _ => false, - } + matches!( + err, + InvalidCrc + | FlowError + | Timeout + | TaskRestarted + | Deserialization + | Desynchronized + ) } _ => false, } @@ -186,7 +190,7 @@ impl From for RequestError { impl From for Result> { fn from(err: DumpOrSprotError) -> Self { - Err(RequestError::Runtime(err.into())) + Err(RequestError::Runtime(err)) } } diff --git a/drv/sprot-api/src/lib.rs b/drv/sprot-api/src/lib.rs index c429393cd..38a25d50e 100644 --- a/drv/sprot-api/src/lib.rs +++ b/drv/sprot-api/src/lib.rs @@ -51,20 +51,16 @@ pub const CURRENT_VERSION: Version = Version(4); /// We allow room in the buffer for message evolution pub const REQUEST_BUF_SIZE: usize = 1024; -// We add 1 byte for padding a maximum sized message to an even number of bytes -// if necessary. const_assert!( REQUEST_BUF_SIZE - >= Header::MAX_SIZE + ReqBody::MAX_SIZE + MAX_BLOB_SIZE + CRC_SIZE + 1 + > Header::MAX_SIZE + ReqBody::MAX_SIZE + MAX_BLOB_SIZE + CRC_SIZE ); /// We allow room in the buffer for message evolution pub const RESPONSE_BUF_SIZE: usize = 1024; -// We add 1 byte for padding a maximum sized message to an even number of bytes -// if necessary. const_assert!( RESPONSE_BUF_SIZE - >= Header::MAX_SIZE + RspBody::MAX_SIZE + MAX_BLOB_SIZE + CRC_SIZE + 1 + > Header::MAX_SIZE + RspBody::MAX_SIZE + MAX_BLOB_SIZE + CRC_SIZE ); // For simplicity we want to be able to retrieve the header @@ -420,6 +416,7 @@ pub enum AttestRsp { /// /// See [`Msg`] for details about versioning and message evolution. #[derive(Clone, Serialize, Deserialize, SerializedSize, From)] +#[allow(clippy::large_enum_variant)] pub enum RspBody { // General Ok status shared among response variants Ok, @@ -596,7 +593,7 @@ impl SpRot { key: [u8; 4], buf: &mut [u8], ) -> Result { - let reader = RotCabooseReader::new(slot_id, &self)?; + let reader = RotCabooseReader::new(slot_id, self)?; let len = reader.get(key, buf)?; Ok(len) } diff --git a/drv/stm32fx-usart/src/main.rs b/drv/stm32fx-usart/src/main.rs index bcff729df..d0e801900 100644 --- a/drv/stm32fx-usart/src/main.rs +++ b/drv/stm32fx-usart/src/main.rs @@ -130,7 +130,7 @@ fn main() -> ! { let txe = usart.sr.read().txe().bit(); if txe { // TX register empty. Do we need to send something? - step_transmit(&usart, txref); + step_transmit(usart, txref); } sys_irq_control(notifications::USART_IRQ_MASK, true); @@ -241,7 +241,7 @@ fn step_transmit( state: &mut Option, ) -> hl::Caller<()> { usart.cr1.modify(|_, w| w.txeie().disabled()); - core::mem::replace(state, None).unwrap().caller + state.take().unwrap().caller } let txs = if let Some(txs) = tx { txs } else { return }; diff --git a/drv/stm32h7-spi-server-core/build.rs b/drv/stm32h7-spi-server-core/build.rs index 61c23f194..5a367e6f0 100644 --- a/drv/stm32h7-spi-server-core/build.rs +++ b/drv/stm32h7-spi-server-core/build.rs @@ -120,8 +120,7 @@ fn check_spi_config( return Err(anyhow!( "bad controller {}, valid values are 1 thru 6", config.controller - ) - .into()); + )); } for mux in config.mux_options.values() { @@ -137,8 +136,7 @@ fn check_spi_config( "device {} names undefined mux {}", devname, dev.mux - ) - .into()); + )); } for pin in &dev.cs { @@ -156,16 +154,14 @@ fn check_afpinset(config: &AfPinSetConfig) -> Result<()> { "pin {:?}{} is invalid, pins are numbered 0-15", config.port, pin - ) - .into()); + )); } } if config.af.0 > 15 { return Err(anyhow!( "af {:?} is invalid, functions are numbered 0-15", config.af - ) - .into()); + )); } Ok(()) } @@ -176,8 +172,7 @@ fn check_afpin(config: &AfPinConfig) -> Result<()> { return Err(anyhow!( "af {:?} is invalid, functions are numbered 0-15", config.af - ) - .into()); + )); } Ok(()) } @@ -188,8 +183,7 @@ fn check_gpiopin(config: &GpioPinConfig) -> Result<()> { "pin {:?}{} is invalid, pins are numbered 0-15", config.port, config.pin - ) - .into()); + )); } Ok(()) } diff --git a/drv/stm32h7-sprot-server/src/main.rs b/drv/stm32h7-sprot-server/src/main.rs index e555956f3..f934f9840 100644 --- a/drv/stm32h7-sprot-server/src/main.rs +++ b/drv/stm32h7-sprot-server/src/main.rs @@ -267,7 +267,7 @@ impl Io { // Read the `Header` self.spi.read(&mut rx_buf[..part1_size])?; - let (header, _) = hubpack::deserialize::
(&rx_buf)?; + let (header, _) = hubpack::deserialize::
(rx_buf)?; let total_size = Header::MAX_SIZE + header.body_size as usize + CRC_SIZE; let part2_size = total_size.saturating_sub(part1_size); @@ -499,7 +499,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { _: &RecvMessage, ) -> Result> { ringbuf_entry!(Trace::StatusReq); - let tx_size = Request::pack(&ReqBody::Status, &mut self.tx_buf); + let tx_size = Request::pack(&ReqBody::Status, self.tx_buf); let rsp = self.do_send_recv_retries( tx_size, TIMEOUT_QUICK, @@ -526,7 +526,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { &mut self, _: &RecvMessage, ) -> Result> { - let tx_size = Request::pack(&ReqBody::IoStats, &mut self.tx_buf); + let tx_size = Request::pack(&ReqBody::IoStats, self.tx_buf); let rsp = self.do_send_recv_retries( tx_size, TIMEOUT_QUICK, @@ -547,7 +547,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { &mut self, _: &RecvMessage, ) -> Result> { - let tx_size = Request::pack(&ReqBody::RotState, &mut self.tx_buf); + let tx_size = Request::pack(&ReqBody::RotState, self.tx_buf); let rsp = self.do_send_recv_retries( tx_size, TIMEOUT_QUICK, @@ -566,7 +566,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { _msg: &userlib::RecvMessage, ) -> Result> { let body = ReqBody::Update(UpdateReq::BootInfo); - let tx_size = Request::pack(&body, &mut self.tx_buf); + let tx_size = Request::pack(&body, self.tx_buf); let rsp = self.do_send_recv_retries( tx_size, TIMEOUT_QUICK, @@ -585,7 +585,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { _msg: &userlib::RecvMessage, ) -> Result> { let body = ReqBody::Update(UpdateReq::GetBlockSize); - let tx_size = Request::pack(&body, &mut self.tx_buf); + let tx_size = Request::pack(&body, self.tx_buf); let rsp = self.do_send_recv_retries( tx_size, TIMEOUT_QUICK, @@ -605,7 +605,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { target: UpdateTarget, ) -> Result<(), idol_runtime::RequestError> { let body = ReqBody::Update(UpdateReq::Prep(target)); - let tx_size = Request::pack(&body, &mut self.tx_buf); + let tx_size = Request::pack(&body, self.tx_buf); let rsp = self.do_send_recv_retries( tx_size, TIMEOUT_QUICK, @@ -629,7 +629,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { >, ) -> Result<(), idol_runtime::RequestError> { let body = ReqBody::Update(UpdateReq::WriteBlock { block_num }); - let tx_size = Request::pack_with_blob(&body, &mut self.tx_buf, block)?; + let tx_size = Request::pack_with_blob(&body, self.tx_buf, block)?; let rsp = self.do_send_recv_retries( tx_size, @@ -649,7 +649,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { _msg: &userlib::RecvMessage, ) -> Result<(), idol_runtime::RequestError> { let body = ReqBody::Update(UpdateReq::Finish); - let tx_size = Request::pack(&body, &mut self.tx_buf); + let tx_size = Request::pack(&body, self.tx_buf); let rsp = self.do_send_recv_retries( tx_size, TIMEOUT_QUICK, @@ -667,7 +667,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { _msg: &userlib::RecvMessage, ) -> Result<(), idol_runtime::RequestError> { let body = ReqBody::Update(UpdateReq::Abort); - let tx_size = Request::pack(&body, &mut self.tx_buf); + let tx_size = Request::pack(&body, self.tx_buf); let rsp = self.do_send_recv_retries( tx_size, TIMEOUT_QUICK, @@ -688,7 +688,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { ) -> Result<(), idol_runtime::RequestError> { let body = ReqBody::Update(UpdateReq::SwitchDefaultImage { slot, duration }); - let tx_size = Request::pack(&body, &mut self.tx_buf); + let tx_size = Request::pack(&body, self.tx_buf); let rsp = self.do_send_recv_retries( tx_size, TIMEOUT_QUICK, @@ -707,7 +707,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { _msg: &userlib::RecvMessage, ) -> Result<(), idol_runtime::RequestError> { let body = ReqBody::Update(UpdateReq::Reset); - let tx_size = Request::pack(&body, &mut self.tx_buf); + let tx_size = Request::pack(&body, self.tx_buf); let rsp = self.do_send_recv_retries(tx_size, TIMEOUT_QUICK, 1)?; if let RspBody::Ok = rsp.body? { Ok(()) @@ -723,7 +723,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { addr: u32, ) -> Result<(), idol_runtime::RequestError> { let body = ReqBody::Dump(DumpReq::V1 { addr }); - let tx_size = Request::pack(&body, &mut self.tx_buf); + let tx_size = Request::pack(&body, self.tx_buf); let rsp = self.do_send_recv_retries(tx_size, DUMP_TIMEOUT, 1)?; if let RspBody::Dump(DumpRsp::V1 { err }) = rsp.body? { err.map_or(Ok(()), |e| DumpOrSprotError::Dump(e).into()) @@ -738,7 +738,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { slot: SlotId, ) -> Result> { let body = ReqBody::Caboose(CabooseReq::Size { slot }); - let tx_size = Request::pack(&body, &mut self.tx_buf); + let tx_size = Request::pack(&body, self.tx_buf); let rsp = self .do_send_recv_retries(tx_size, DUMP_TIMEOUT, 1) .map_err(RawCabooseOrSprotError::Sprot)?; @@ -769,7 +769,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { start: offset, size: data.len() as u32, }); - let tx_size = Request::pack(&body, &mut self.tx_buf); + let tx_size = Request::pack(&body, self.tx_buf); let rsp = self .do_send_recv_retries(tx_size, DUMP_TIMEOUT, 4) .map_err(RawCabooseOrSprotError::Sprot)?; @@ -815,7 +815,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { offset, size: data.len() as u32, }); - let tx_size = Request::pack(&body, &mut self.tx_buf); + let tx_size = Request::pack(&body, self.tx_buf); let rsp = self .do_send_recv_retries(tx_size, DUMP_TIMEOUT, DEFAULT_ATTEMPTS) .map_err(AttestOrSprotError::Sprot)?; @@ -852,7 +852,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { _: &userlib::RecvMessage, ) -> Result> { let body = ReqBody::Attest(AttestReq::CertChainLen); - let tx_size = Request::pack(&body, &mut self.tx_buf); + let tx_size = Request::pack(&body, self.tx_buf); let rsp = self.do_send_recv_retries(tx_size, TIMEOUT_QUICK, 1)?; match rsp.body { Ok(RspBody::Attest(Ok(AttestRsp::CertChainLen(s)))) => Ok(s), @@ -873,7 +873,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { index: u32, ) -> Result> { let body = ReqBody::Attest(AttestReq::CertLen(index)); - let tx_size = Request::pack(&body, &mut self.tx_buf); + let tx_size = Request::pack(&body, self.tx_buf); let rsp = self.do_send_recv_retries(tx_size, TIMEOUT_QUICK, 1)?; match rsp.body { Ok(RspBody::Attest(Ok(AttestRsp::CertLen(s)))) => Ok(s), @@ -898,7 +898,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { >, ) -> Result<(), idol_runtime::RequestError> { let body = ReqBody::Attest(AttestReq::Record { algorithm }); - let tx_size = Request::pack_with_blob(&body, &mut self.tx_buf, data)?; + let tx_size = Request::pack_with_blob(&body, self.tx_buf, data)?; let rsp = self.do_send_recv_retries(tx_size, TIMEOUT_QUICK, 1)?; match rsp.body { @@ -919,7 +919,7 @@ impl idl::InOrderSpRotImpl for ServerImpl { ) -> Result<(), idol_runtime::RequestError> { ringbuf_entry!(Trace::RotPage); let body = ReqBody::RotPage { page }; - let tx_size = Request::pack(&body, &mut self.tx_buf); + let tx_size = Request::pack(&body, self.tx_buf); let rsp = self.do_send_recv_retries( tx_size, TIMEOUT_MEDIUM, diff --git a/drv/stm32h7-update-server/src/main.rs b/drv/stm32h7-update-server/src/main.rs index 9025010a8..9ac1f5a10 100644 --- a/drv/stm32h7-update-server/src/main.rs +++ b/drv/stm32h7-update-server/src/main.rs @@ -171,8 +171,7 @@ impl<'a> ServerImpl<'a> { // SAFETY: these are symbols populated by the linker. let bank_addr = unsafe { __REGION_BANK2_BASE.as_ptr() } as usize; let bank_end = unsafe { __REGION_BANK2_END.as_ptr() } as usize; - let bank_word_limit = - (bank_end - bank_addr) as usize / FLASH_WORD_BYTES; + let bank_word_limit = (bank_end - bank_addr) / FLASH_WORD_BYTES; if word_number > bank_word_limit { panic!(); diff --git a/drv/stm32xx-i2c-server/src/main.rs b/drv/stm32xx-i2c-server/src/main.rs index 3dba253d0..b350fa738 100644 --- a/drv/stm32xx-i2c-server/src/main.rs +++ b/drv/stm32xx-i2c-server/src/main.rs @@ -273,15 +273,15 @@ fn reset( } fn reset_needed(code: ResponseCode) -> bool { - match code { + matches!( + code, ResponseCode::BusLocked - | ResponseCode::BusLockedMux - | ResponseCode::BusReset - | ResponseCode::BusResetMux - | ResponseCode::BusError - | ResponseCode::ControllerBusy => true, - _ => false, - } + | ResponseCode::BusLockedMux + | ResponseCode::BusReset + | ResponseCode::BusResetMux + | ResponseCode::BusError + | ResponseCode::ControllerBusy + ) } fn reset_if_needed( diff --git a/drv/transceivers-server/src/main.rs b/drv/transceivers-server/src/main.rs index 6131204b6..28497f728 100644 --- a/drv/transceivers-server/src/main.rs +++ b/drv/transceivers-server/src/main.rs @@ -332,6 +332,7 @@ impl ServerImpl { } fn update_thermal_loop(&mut self, status: ModuleStatus) { + #[allow(clippy::needless_range_loop)] for i in 0..self.thermal_models.len() { let port = LogicalPort(i as u8); let mask = 1 << i; @@ -655,6 +656,7 @@ fn main() -> ! { // There are two timers, one for each communication bus: #[derive(Copy, Clone, Enum)] + #[allow(clippy::upper_case_acronyms)] enum Timers { I2C, SPI, diff --git a/lib/dice/src/mfg.rs b/lib/dice/src/mfg.rs index 824b3c510..1b338867a 100644 --- a/lib/dice/src/mfg.rs +++ b/lib/dice/src/mfg.rs @@ -388,7 +388,7 @@ impl DiceMfg for SerialMfg<'_> { /// Write all bytes in buf to usart fifo, poll if fifo is full. /// NOTE: This does not guarantee transmission of all bytes. See flush_all. -fn write_all(usart: &mut Usart, src: &[u8]) -> Result<(), Error> { +fn write_all(usart: &mut Usart<'_>, src: &[u8]) -> Result<(), Error> { for b in src { let _ = nb::block!(usart.write(*b)).map_err(|_| Error::UsartWrite); } @@ -398,7 +398,7 @@ fn write_all(usart: &mut Usart, src: &[u8]) -> Result<(), Error> { /// Poll the usart reading bytes into dst until a termination sequence is /// found. pub fn read_until_zero( - usart: &mut Usart, + usart: &mut Usart<'_>, dst: &mut [u8], ) -> Result { if dst.is_empty() { @@ -425,7 +425,7 @@ pub fn read_until_zero( /// Like 'flush' from embedded-hal 'Write' trait but polls till the transmit /// FIFO is empty. -pub fn flush_all(usart: &mut Usart) { +pub fn flush_all(usart: &mut Usart<'_>) { // flush only returns WouldBlock and nb::block eats that let _ = nb::block!(usart.flush()); } diff --git a/lib/lpc55-puf/src/lib.rs b/lib/lpc55-puf/src/lib.rs index d465d78f6..1b3a7236b 100644 --- a/lib/lpc55-puf/src/lib.rs +++ b/lib/lpc55-puf/src/lib.rs @@ -328,10 +328,7 @@ impl<'a> Puf<'a> { } fn is_locked(&self, idxblk: u32) -> bool { - match self.get_lock_state(idxblk) { - Some(LockState::Locked) => true, - _ => false, - } + matches!(self.get_lock_state(idxblk), Some(LockState::Locked)) } pub fn is_idxblk_l_locked(&self) -> bool { diff --git a/lib/lpc55-rot-startup/build.rs b/lib/lpc55-rot-startup/build.rs index fc708ec04..5a189a2a7 100644 --- a/lib/lpc55-rot-startup/build.rs +++ b/lib/lpc55-rot-startup/build.rs @@ -25,7 +25,7 @@ fn main() -> Result<(), Box> { writeln!( cfg, "#[allow(dead_code)]\npub const FLASH_{}: Range = {:#x}..{:#x};", - region.name.replace("-", "_").to_uppercase(), + region.name.replace('-', "_").to_uppercase(), region.address, region.address + region.size )?; diff --git a/lib/lpc55-rot-startup/src/dice.rs b/lib/lpc55-rot-startup/src/dice.rs index ff53cb6fe..57bdf01ad 100644 --- a/lib/lpc55-rot-startup/src/dice.rs +++ b/lib/lpc55-rot-startup/src/dice.rs @@ -35,7 +35,7 @@ pub struct MfgResult { /// Generate stuff associated with the manufacturing process. fn gen_mfg_artifacts( peripherals: &Peripherals, - flash: &mut Flash, + flash: &mut Flash<'_>, ) -> MfgResult { // Select manufacturing process based on feature. This module assumes // that one of the manufacturing flavors has been enabled. @@ -56,7 +56,7 @@ fn gen_mfg_artifacts( #[cfg(feature = "dice-self")] fn gen_mfg_artifacts_self( peripherals: &Peripherals, - _flash: &mut Flash, + _flash: &mut Flash<'_>, ) -> MfgResult { use core::ops::{Deref, DerefMut}; use lib_dice::{DiceMfg, PersistIdSeed, SelfMfg}; @@ -115,7 +115,7 @@ fn gen_deviceid_artifacts( persistid_keypair: Keypair, persistid_cert: PersistIdCert, intermediate_cert: Option, - handoff: &Handoff, + handoff: &Handoff<'_>, ) -> Keypair { let devid_okm = DeviceIdOkm::from_cdi(cdi); @@ -123,7 +123,7 @@ fn gen_deviceid_artifacts( let deviceid_cert = DeviceIdCertBuilder::new( &cert_serial_number.next_num(), - &platform_id, + platform_id, &deviceid_keypair.public, ) .sign(&persistid_keypair); @@ -146,9 +146,9 @@ fn gen_alias_artifacts( cert_serial_number: &mut CertSerialNumber, deviceid_keypair: &Keypair, fwid: &[u8; 32], - handoff: &Handoff, + handoff: &Handoff<'_>, ) { - let alias_okm = AliasOkm::from_cdi(&cdi_l1); + let alias_okm = AliasOkm::from_cdi(cdi_l1); let alias_keypair = Keypair::from(alias_okm.as_bytes()); let alias_cert = AliasCertBuilder::new( @@ -156,9 +156,9 @@ fn gen_alias_artifacts( &alias_keypair.public, fwid, ) - .sign(&deviceid_keypair); + .sign(deviceid_keypair); - let tqdhe_okm = TrustQuorumDheOkm::from_cdi(&cdi_l1); + let tqdhe_okm = TrustQuorumDheOkm::from_cdi(cdi_l1); let tqdhe_keypair = Keypair::from(tqdhe_okm.as_bytes()); let tqdhe_cert = TrustQuorumDheCertBuilder::new( @@ -166,7 +166,7 @@ fn gen_alias_artifacts( &tqdhe_keypair.public, fwid, ) - .sign(&deviceid_keypair); + .sign(deviceid_keypair); let alias_data = AliasData::new(alias_okm, alias_cert, tqdhe_okm, tqdhe_cert); @@ -181,9 +181,9 @@ fn gen_spmeasure_artifacts( cert_serial_number: &mut CertSerialNumber, deviceid_keypair: &Keypair, fwid: &[u8; 32], - handoff: &Handoff, + handoff: &Handoff<'_>, ) { - let spmeasure_okm = SpMeasureOkm::from_cdi(&cdi_l1); + let spmeasure_okm = SpMeasureOkm::from_cdi(cdi_l1); let spmeasure_keypair = Keypair::from(spmeasure_okm.as_bytes()); let spmeasure_cert = SpMeasureCertBuilder::new( @@ -191,7 +191,7 @@ fn gen_spmeasure_artifacts( &spmeasure_keypair.public, fwid, ) - .sign(&deviceid_keypair); + .sign(deviceid_keypair); let spmeasure_data = SpMeasureData::new(spmeasure_okm, spmeasure_cert); @@ -199,7 +199,7 @@ fn gen_spmeasure_artifacts( } /// Generate seed for the RNG task to seed its RNG. -fn gen_rng_artifacts(cdi_l1: &CdiL1, handoff: &Handoff) { +fn gen_rng_artifacts(cdi_l1: &CdiL1, handoff: &Handoff<'_>) { let rng_seed = RngSeed::from_cdi(cdi_l1); let rng_data = RngData::new(rng_seed); @@ -210,7 +210,11 @@ fn gen_rng_artifacts(cdi_l1: &CdiL1, handoff: &Handoff) { // will contain sensitive material, from commingling with the caller. Do not // remove it without reconsidering our stack zeroization approach. #[inline(never)] -pub fn run(handoff: &Handoff, peripherals: &Peripherals, flash: &mut Flash) { +pub fn run( + handoff: &Handoff<'_>, + peripherals: &Peripherals, + flash: &mut Flash<'_>, +) { // The memory we use to handoff DICE artifacts is already enabled // in `main()`; @@ -222,7 +226,7 @@ pub fn run(handoff: &Handoff, peripherals: &Peripherals, flash: &mut Flash) { None => return, }; - let mut mfg_data = gen_mfg_artifacts(&peripherals, flash); + let mut mfg_data = gen_mfg_artifacts(peripherals, flash); let deviceid_keypair = gen_deviceid_artifacts( &cdi, diff --git a/lib/lpc55-rot-startup/src/dice_mfg_usart.rs b/lib/lpc55-rot-startup/src/dice_mfg_usart.rs index 1d5ce0a48..b6d47efc0 100644 --- a/lib/lpc55-rot-startup/src/dice_mfg_usart.rs +++ b/lib/lpc55-rot-startup/src/dice_mfg_usart.rs @@ -106,7 +106,10 @@ impl DiceState { Ok(state) } - pub fn to_flash(&self, flash: &mut Flash) -> Result { + pub fn to_flash( + &self, + flash: &mut Flash<'_>, + ) -> Result { let mut buf = [0u8; Self::ALIGNED_MAX_SIZE]; let header = Header::default(); @@ -132,9 +135,9 @@ impl DiceState { Ok(offset) } - pub fn is_programmed(flash: &mut Flash) -> bool { + pub fn is_programmed(flash: &mut Flash<'_>) -> bool { flash.is_page_range_programmed( - FLASH_DICE_MFG.start as u32, + FLASH_DICE_MFG.start, flash_page_align!(Header::MAX_SIZE + Self::MAX_SIZE) as u32, ) } @@ -154,7 +157,7 @@ fn delay() { /// manufacturing line. fn gen_artifacts_from_mfg( peripherals: &Peripherals, - flash: &mut Flash, + flash: &mut Flash<'_>, ) -> MfgResult { let puf = Puf::new(&peripherals.PUF); @@ -251,7 +254,7 @@ fn gen_artifacts_from_flash(peripherals: &Peripherals) -> MfgResult { pub fn gen_mfg_artifacts_usart( peripherals: &Peripherals, - flash: &mut Flash, + flash: &mut Flash<'_>, ) -> MfgResult { if DiceState::is_programmed(flash) { gen_artifacts_from_flash(peripherals) diff --git a/lib/lpc55-rot-startup/src/images.rs b/lib/lpc55-rot-startup/src/images.rs index 70ddb4f7a..f7e7731c4 100644 --- a/lib/lpc55-rot-startup/src/images.rs +++ b/lib/lpc55-rot-startup/src/images.rs @@ -8,7 +8,7 @@ use sha3::{Digest, Sha3_256}; use stage0_handoff::{ImageVersion, RotImageDetails}; use unwrap_lite::UnwrapLite; -pub fn get_image_b(flash: &mut Flash) -> Option { +pub fn get_image_b(flash: &mut Flash<'_>) -> Option { let imageb = unsafe { &__IMAGE_B_BASE }; let img = Image { @@ -23,7 +23,7 @@ pub fn get_image_b(flash: &mut Flash) -> Option { } } -pub fn get_image_a(flash: &mut Flash) -> Option { +pub fn get_image_a(flash: &mut Flash<'_>) -> Option { let imagea = unsafe { &__IMAGE_A_BASE }; let img = Image { @@ -60,7 +60,7 @@ pub struct Image { vector: &'static ImageVectors, } -pub fn image_details(img: Image, flash: &mut Flash) -> RotImageDetails { +pub fn image_details(img: Image, flash: &mut Flash<'_>) -> RotImageDetails { RotImageDetails { digest: img.get_fwid(flash), version: img.get_image_version(), @@ -86,7 +86,7 @@ impl Image { } /// Make sure all of the image flash is programmed - fn validate(&self, flash: &mut Flash) -> bool { + fn validate(&self, flash: &mut Flash<'_>) -> bool { let img_start = self.get_img_start(); // Start by making sure we can access the page where the vectors live @@ -122,17 +122,11 @@ impl Image { None => return false, }; - // Next make sure the marked image length is programmed - let valid = flash.is_page_range_programmed(img_start, total_len); - - if !valid { - return false; - } - - return true; + // Last step is to make sure the entire range is programmed + flash.is_page_range_programmed(img_start, total_len) } - pub fn get_fwid(&self, flash: &mut Flash) -> [u8; 32] { + pub fn get_fwid(&self, flash: &mut Flash<'_>) -> [u8; 32] { let mut hash = Sha3_256::new(); for start in self.flash.clone().step_by(BYTES_PER_FLASH_PAGE) { @@ -169,7 +163,7 @@ impl Image { // The MPU requires 32 byte alignment and so the compiler pads the // image accordingly. The length field from the image header does not // (and should not) account for this padding so we must do that here. - let img_size = self.get_img_size().unwrap_lite() + 31 & !31; + let img_size = (self.get_img_size().unwrap_lite() + 31) & !31; // Safety: this is unsafe because the pointer addition could overflow. // If that happens, we'll produce an empty range or crash with a panic. diff --git a/lib/lpc55-rot-startup/src/lib.rs b/lib/lpc55-rot-startup/src/lib.rs index 3bb6c9175..42f7fe9d7 100644 --- a/lib/lpc55-rot-startup/src/lib.rs +++ b/lib/lpc55-rot-startup/src/lib.rs @@ -31,7 +31,7 @@ const ROM_VER: u32 = 1; // them to apply for now while we write that memory. fn apply_memory_protection(mpu: &MPU) { unsafe { - disable_mpu(&mpu); + disable_mpu(mpu); } const USB_RAM_BASE: u32 = 0x4010_0000; @@ -59,7 +59,7 @@ fn apply_memory_protection(mpu: &MPU) { } unsafe { - enable_mpu(&mpu, true); + enable_mpu(mpu, true); } } @@ -164,7 +164,7 @@ pub fn startup( apply_memory_protection(mpu); #[cfg(any(feature = "dice-mfg", feature = "dice-self"))] - dice::run(&handoff, &peripherals, &mut flash); + dice::run(&handoff, peripherals, &mut flash); nuke_stack(); @@ -192,7 +192,7 @@ pub fn startup( // This is purposely done as the very last step after all validation // and secret clearing has happened - enable_debug(&peripherals); + enable_debug(peripherals); } // When we're secure we don't have access to read the CMPA/NMPA where the diff --git a/lib/task-config/src/lib.rs b/lib/task-config/src/lib.rs index bd9d88951..1078e817e 100644 --- a/lib/task-config/src/lib.rs +++ b/lib/task-config/src/lib.rs @@ -12,7 +12,7 @@ struct Config { items: Punctuated, } impl Parse for Config { - fn parse(input: ParseStream) -> Result { + fn parse(input: ParseStream<'_>) -> Result { Ok(Self { items: input.parse_terminated(Field::parse_named)?, }) @@ -32,12 +32,14 @@ fn config_to_token( syn::Type::Tuple(a) => { let v: Vec = v .as_array() - .expect(&format!( - "Expected TOML array for tuple type {}; got {}", - ty.to_token_stream().to_string(), - v - )) - .into_iter() + .unwrap_or_else(|| { + panic!( + "Expected TOML array for tuple type {}; got {}", + ty.to_token_stream(), + v + ) + }) + .iter() .zip(a.elems.iter()) .map(|(v, t)| config_to_token(t, v)) .collect(); @@ -46,12 +48,14 @@ fn config_to_token( syn::Type::Array(a) => { let v: Vec = v .as_array() - .expect(&format!( - "Expected TOML array for array type {}; got {}", - ty.to_token_stream().to_string(), - v - )) - .into_iter() + .unwrap_or_else(|| { + panic!( + "Expected TOML array for array type {}; got {}", + ty.to_token_stream(), + v + ) + }) + .iter() .map(|v| config_to_token(&a.elem, v)) .collect(); quote! { [ #(#v),* ] } @@ -59,12 +63,14 @@ fn config_to_token( syn::Type::Slice(s) => { let v: Vec = v .as_array() - .expect(&format!( - "Expected TOML array for slice type {}; got {}", - ty.to_token_stream().to_string(), - v - )) - .into_iter() + .unwrap_or_else(|| { + panic!( + "Expected TOML array for slice type {}; got {}", + ty.to_token_stream(), + v + ) + }) + .iter() .map(|v| config_to_token(&s.elem, v)) .collect(); quote! { [ #(#v),* ] } @@ -84,10 +90,10 @@ fn config_to_token( v.to_string() }; v.parse() - .expect(&format!("Could not parse {}", v.to_string())) + .unwrap_or_else(|_| panic!("Could not parse {}", v)) } _ => { - panic!("Got unhandled type {}", ty.to_token_stream().to_string()) + panic!("Got unhandled type {}", ty.to_token_stream()) } } } @@ -149,10 +155,9 @@ pub fn task_config(tokens: TokenStream) -> TokenStream { .iter() .map(|f| { let ident = f.ident.as_ref().expect("Missing ident"); - let v = config.get(ident.to_string()).expect(&format!( - "Missing config parameter in TOML file: {}", - ident.to_string() - )); + let v = config.get(ident.to_string()).unwrap_or_else(|| { + panic!("Missing config parameter in TOML file: {}", ident) + }); let vs = config_to_token(&f.ty, v); quote! { #ident: #vs } }) @@ -192,10 +197,9 @@ pub fn optional_task_config(tokens: TokenStream) -> TokenStream { .iter() .map(|f| { let ident = f.ident.as_ref().expect("Missing ident"); - let v = config.get(ident.to_string()).expect(&format!( - "Missing config parameter in TOML file: {}", - ident.to_string() - )); + let v = config.get(ident.to_string()).unwrap_or_else(|| { + panic!("Missing config parameter in TOML file: {}", ident) + }); let vs = config_to_token(&f.ty, v); quote! { #ident: #vs } }) @@ -209,7 +213,6 @@ pub fn optional_task_config(tokens: TokenStream) -> TokenStream { #(#values),* }) } - .into() } else { quote! { None } }; diff --git a/sys/kern/build.rs b/sys/kern/build.rs index 252230ddd..ad78672cd 100644 --- a/sys/kern/build.rs +++ b/sys/kern/build.rs @@ -200,10 +200,10 @@ fn process_config() -> Result { quote::quote! { pub const HUBRIS_IRQ_TASK_LOOKUP: - phash::SortedList + phash::SortedList<'_, abi::InterruptNum, abi::InterruptOwner> = #irq_task_literal; pub const HUBRIS_TASK_IRQ_LOOKUP: - phash::SortedList< + phash::SortedList<'_, abi::InterruptOwner, &'static [abi::InterruptNum], > = #task_irq_literal; diff --git a/sys/kern/src/arch/arm_m.rs b/sys/kern/src/arch/arm_m.rs index fa9feafe8..f1ab8a03a 100644 --- a/sys/kern/src/arch/arm_m.rs +++ b/sys/kern/src/arch/arm_m.rs @@ -489,11 +489,11 @@ pub fn apply_memory_protection(task: &task::Task) { mpu.rlar.write(rlar); // configure but leave disabled if rnr < 4 { let mut mair0 = mpu.mair[0].read(); - mair0 |= (mair as u32) << (rnr * 8); + mair0 |= mair << (rnr * 8); mpu.mair[0].write(mair0); } else { let mut mair1 = mpu.mair[1].read(); - mair1 |= (mair as u32) << ((rnr - 4) * 8); + mair1 |= mair << ((rnr - 4) * 8); mpu.mair[1].write(mair1); } mpu.rbar.write(rbar); @@ -814,7 +814,7 @@ pub unsafe extern "C" fn SVCall() { mov lr, r0 bx lr @ branch into user mode ", - exc_return = const EXC_RETURN_CONST as u32, + exc_return = const EXC_RETURN_CONST, options(noreturn), ) } else if #[cfg(any(armv7m, armv8m))] { diff --git a/sys/kern/src/fail.rs b/sys/kern/src/fail.rs index 906a781e9..a27f762a5 100644 --- a/sys/kern/src/fail.rs +++ b/sys/kern/src/fail.rs @@ -89,7 +89,7 @@ impl Write for Eulogist { let s = s.as_bytes(); let n = s.len().min(self.dest.len()); let (dest, leftovers) = { - let taken = core::mem::replace(&mut self.dest, &mut []); + let taken = core::mem::take(&mut self.dest); taken.split_at_mut(n) }; dest.copy_from_slice(&s[..n]); diff --git a/sys/kern/src/kipc.rs b/sys/kern/src/kipc.rs index 78d5314c7..9a87d0e30 100644 --- a/sys/kern/src/kipc.rs +++ b/sys/kern/src/kipc.rs @@ -364,7 +364,7 @@ fn read_task_dump_region( // succeed (see: the comparisons between base+size and region.size // above). let offset = from.base_addr() - tcb_base; - let tcb = &target_task[offset as usize..from.len()]; + let tcb = &target_task[offset..from.len()]; let to = caller_task .try_write(&mut response) diff --git a/task/control-plane-agent/src/mgs_common.rs b/task/control-plane-agent/src/mgs_common.rs index 6fd0f6748..60ec99505 100644 --- a/task/control-plane-agent/src/mgs_common.rs +++ b/task/control-plane-agent/src/mgs_common.rs @@ -166,7 +166,7 @@ impl MgsCommon { .map_err(caboose_to_sp_error)?; Ok(len as usize) } - _ => return Err(SpError::InvalidSlotForComponent), + _ => Err(SpError::InvalidSlotForComponent), }, SpComponent::ROT => { let slot_id = slot @@ -178,7 +178,7 @@ impl MgsCommon { .map_err(caboose_or_sprot_to_sp_error)?; Ok(len as usize) } - _ => return Err(SpError::RequestUnsupportedForComponent), + _ => Err(SpError::RequestUnsupportedForComponent), } } @@ -291,7 +291,7 @@ impl MgsCommon { }; Ok(slot) } - _ => return Err(SpError::RequestUnsupportedForComponent), + _ => Err(SpError::RequestUnsupportedForComponent), } } @@ -322,7 +322,7 @@ impl MgsCommon { // enables SwitchDuration::Once. // // Other components might also be served someday. - _ => return Err(SpError::RequestUnsupportedForComponent), + _ => Err(SpError::RequestUnsupportedForComponent), } } diff --git a/task/dump-agent/src/main.rs b/task/dump-agent/src/main.rs index 7deb44388..6fc0de8ab 100644 --- a/task/dump-agent/src/main.rs +++ b/task/dump-agent/src/main.rs @@ -53,11 +53,11 @@ impl ServerImpl { length: u32, ) -> Result<(), DumpAgentError> { if addr & 0b11 != 0 { - return Err(DumpAgentError::UnalignedSegmentAddress.into()); + return Err(DumpAgentError::UnalignedSegmentAddress); } if (length as usize) & 0b11 != 0 { - return Err(DumpAgentError::UnalignedSegmentLength.into()); + return Err(DumpAgentError::UnalignedSegmentLength); } let area = self.dump_area(0)?; @@ -106,8 +106,12 @@ impl ServerImpl { let base = area.region.address as *const u8; let base = unsafe { base.add(offset as usize) }; - for i in 0..usize::min(to_read as usize, DUMP_READ_SIZE) { - rval[i] = unsafe { core::ptr::read_volatile(base.add(i)) }; + for (i, entry) in rval + .iter_mut() + .enumerate() + .take(usize::min(to_read as usize, DUMP_READ_SIZE)) + { + *entry = unsafe { core::ptr::read_volatile(base.add(i)) }; } Ok(rval) @@ -152,7 +156,7 @@ impl ServerImpl { match sprot.dump(area.region.address) { Err(DumpOrSprotError::Dump(e)) => Err(e.into()), - Err(_) => Err(DumpAgentError::DumpMessageFailed.into()), + Err(_) => Err(DumpAgentError::DumpMessageFailed), Ok(()) => Ok(()), } } diff --git a/task/dumper/src/main.rs b/task/dumper/src/main.rs index f199e9edb..3688cc35a 100644 --- a/task/dumper/src/main.rs +++ b/task/dumper/src/main.rs @@ -90,17 +90,15 @@ impl idl::InOrderDumperImpl for ServerImpl { let mut nread = 0; let mut nwritten = 0; - let mut reg = 0; let r = humpty::dump::( header.address, None, || { - for r in reg..=31 { + for r in 0..=31 { ringbuf_entry!(Trace::ReadingRegister(r)); match sp_ctrl.read_core_register(r) { Ok(val) => { - reg = r + 1; return Ok(Some(humpty::RegisterRead(r, val))); } Err(SpCtrlError::InvalidCoreRegister) => {} @@ -152,12 +150,10 @@ impl idl::InOrderDumperImpl for ServerImpl { // if sp_ctrl.setup().is_err() { ringbuf_entry!(Trace::ReinitFailed); + } else if sp_ctrl.resume().is_err() { + ringbuf_entry!(Trace::ReinitSucceededButResumeFailed); } else { - if sp_ctrl.resume().is_err() { - ringbuf_entry!(Trace::ReinitSucceededButResumeFailed); - } else { - ringbuf_entry!(Trace::ReinitResumed); - } + ringbuf_entry!(Trace::ReinitResumed); } if r.is_err() { diff --git a/task/hiffy/src/stm32g0.rs b/task/hiffy/src/stm32g0.rs index 192094228..dc2440cd2 100644 --- a/task/hiffy/src/stm32g0.rs +++ b/task/hiffy/src/stm32g0.rs @@ -138,7 +138,7 @@ fn i2c_read( }; let res = if let Some(reg) = register { - device.read_reg_into::(reg as u8, buf) + device.read_reg_into::(reg, buf) } else { device.read_into(buf) }; @@ -152,7 +152,7 @@ fn i2c_read( }; device - .read_block::(reg as u8, buf) + .read_block::(reg, buf) .map_err(|e| Failure::FunctionError(u32::from(e))) } else { Err(Failure::Fault(Fault::EmptyParameter(6))) diff --git a/task/host-sp-comms/src/bsp/gimlet_bcde.rs b/task/host-sp-comms/src/bsp/gimlet_bcde.rs index 33772af3f..90ed8bed8 100644 --- a/task/host-sp-comms/src/bsp/gimlet_bcde.rs +++ b/task/host-sp-comms/src/bsp/gimlet_bcde.rs @@ -631,7 +631,7 @@ impl ServerImpl { } })?; } - Ok(&data) + Ok(data) }); } @@ -684,19 +684,15 @@ impl ServerImpl { vpd_identity, fans: [fan0, fan1, fan2] } = &mut data else { unreachable!(); }; - *identity = read_one_barcode(dev.clone(), &[(*b"BARC", 0)])?.into(); + *identity = read_one_barcode(dev, &[(*b"BARC", 0)])?.into(); *vpd_identity = - read_one_barcode(dev.clone(), &[(*b"SASY", 0), (*b"BARC", 0)])? - .into(); + read_one_barcode(dev, &[(*b"SASY", 0), (*b"BARC", 0)])?.into(); *fan0 = - read_one_barcode(dev.clone(), &[(*b"SASY", 0), (*b"BARC", 1)])? - .into(); + read_one_barcode(dev, &[(*b"SASY", 0), (*b"BARC", 1)])?.into(); *fan1 = - read_one_barcode(dev.clone(), &[(*b"SASY", 0), (*b"BARC", 2)])? - .into(); + read_one_barcode(dev, &[(*b"SASY", 0), (*b"BARC", 2)])?.into(); *fan2 = - read_one_barcode(dev.clone(), &[(*b"SASY", 0), (*b"BARC", 3)])? - .into(); + read_one_barcode(dev, &[(*b"SASY", 0), (*b"BARC", 3)])?.into(); Ok(&data) }) } @@ -707,7 +703,7 @@ fn read_one_barcode( dev: I2cDevice, path: &[([u8; 4], usize)], ) -> Result { - let eeprom = At24Csw080::new(dev.clone()); + let eeprom = At24Csw080::new(dev); let mut barcode = [0; 32]; match drv_oxide_vpd::read_config_nested_from_into( eeprom, diff --git a/task/jefe/build.rs b/task/jefe/build.rs index a8e3db582..fe7c797de 100644 --- a/task/jefe/build.rs +++ b/task/jefe/build.rs @@ -42,7 +42,7 @@ fn main() -> Result<()> { writeln!( out, " ({task}::{name}, crate::notifications::{name}::{}_MASK),", - rec.to_ascii_uppercase().replace("-", "_"), + rec.to_ascii_uppercase().replace('-', "_"), )?; } writeln!(out, "];")?; @@ -97,7 +97,7 @@ struct DumpRegion { fn output_dump_areas(out: &mut std::fs::File) -> Result<()> { let dump_regions = build_util::task_extern_regions::()?; - if dump_regions.len() == 0 { + if dump_regions.is_empty() { anyhow::bail!( "jefe is configured for dumping, but no dump regions have been \ specified via extern_regions" diff --git a/task/jefe/src/dump.rs b/task/jefe/src/dump.rs index dcd7e3113..e39d40183 100644 --- a/task/jefe/src/dump.rs +++ b/task/jefe/src/dump.rs @@ -77,7 +77,7 @@ pub fn initialize_dump_areas() -> u32 { /// that this will only check for containment, not overlap.) /// fn in_dump_area(address: u32, length: u32) -> bool { - if address < DUMP_ADDRESS_MIN || address >= DUMP_ADDRESS_MAX { + if !(DUMP_ADDRESS_MIN..DUMP_ADDRESS_MAX).contains(&address) { return false; } @@ -291,11 +291,11 @@ pub fn dump_task_region( }); if start & 0b11 != 0 { - return Err(DumpAgentError::UnalignedSegmentAddress.into()); + return Err(DumpAgentError::UnalignedSegmentAddress); } if (length as usize) & 0b11 != 0 { - return Err(DumpAgentError::UnalignedSegmentLength.into()); + return Err(DumpAgentError::UnalignedSegmentLength); } let area = dump_task_setup(base, DumpTaskContents::TaskRegion)?; diff --git a/task/jefe/src/main.rs b/task/jefe/src/main.rs index f5110858a..20c0d71cf 100644 --- a/task/jefe/src/main.rs +++ b/task/jefe/src/main.rs @@ -315,30 +315,27 @@ impl idol_runtime::NotificationHandler for ServerImpl<'_> { continue; } - match kipc::read_task_status(i) { - abi::TaskState::Faulted { .. } => { - #[cfg(feature = "dump")] - { - // We'll ignore the result of dumping; it could fail - // if we're out of space, but we don't have a way of - // dealing with that right now. - // - // TODO: some kind of circular buffer? - _ = dump::dump_task(self.dump_areas, i); - } - - if status.disposition == Disposition::Restart { - // Stand it back up - kipc::restart_task(i, true); - } else { - // Mark this one off so we don't revisit it until - // requested. - status.holding_fault = true; - } + if let abi::TaskState::Faulted { .. } = + kipc::read_task_status(i) + { + #[cfg(feature = "dump")] + { + // We'll ignore the result of dumping; it could fail + // if we're out of space, but we don't have a way of + // dealing with that right now. + // + // TODO: some kind of circular buffer? + _ = dump::dump_task(self.dump_areas, i); } - // For the purposes of this loop, ignore all other tasks. - _ => (), + if status.disposition == Disposition::Restart { + // Stand it back up + kipc::restart_task(i, true); + } else { + // Mark this one off so we don't revisit it until + // requested. + status.holding_fault = true; + } } } } diff --git a/task/net/build.rs b/task/net/build.rs index 1cd9f8f9e..098f3c0b1 100644 --- a/task/net/build.rs +++ b/task/net/build.rs @@ -94,7 +94,7 @@ fn generate_owner_info(config: &NetConfig) -> Result { let task: syn::Ident = syn::parse_str(&socket.owner.name).unwrap(); let note: syn::Ident = syn::parse_str(&format!( "{}_MASK", - socket.owner.notification.to_uppercase().replace("-", "_") + socket.owner.notification.to_uppercase().replace('-', "_") )) .unwrap(); Ok(quote::quote! { diff --git a/task/net/src/server.rs b/task/net/src/server.rs index 7a3c04bd8..f061bb6e3 100644 --- a/task/net/src/server.rs +++ b/task/net/src/server.rs @@ -530,6 +530,7 @@ where let socket = vlan .get_socket_mut(socket_index) .ok_or(RequestError::Fail(ClientError::BadMessageContents))?; + #[allow(clippy::while_let_loop)] loop { match socket.recv() { Ok((body, endp)) => { diff --git a/task/packrat/build.rs b/task/packrat/build.rs index 7385c0732..cc765e25c 100644 --- a/task/packrat/build.rs +++ b/task/packrat/build.rs @@ -11,14 +11,13 @@ fn main() -> Result<(), Box> { // Ensure the "gimlet" feature is enabled on gimlet boards. #[cfg(not(feature = "gimlet"))] - match build_util::target_board().as_deref() { - Some("gimlet-b" | "gimlet-c" | "gimlet-d" | "gimlet-e") => { - panic!(concat!( - "packrat's `gimlet` feature should be enabled when ", - "building for gimlets", - )) - } - _ => (), + if let Some("gimlet-b" | "gimlet-c" | "gimlet-d" | "gimlet-e") = + build_util::target_board().as_deref() + { + panic!(concat!( + "packrat's `gimlet` feature should be enabled when ", + "building for gimlets", + )) } // Ensure the "gimlet" feature is _not_ enabled on sidecar/psc boards. diff --git a/task/packrat/src/main.rs b/task/packrat/src/main.rs index c7aea2e9c..c960687f1 100644 --- a/task/packrat/src/main.rs +++ b/task/packrat/src/main.rs @@ -161,7 +161,7 @@ impl idl::InOrderPackratImpl for ServerImpl { _: &RecvMessage, macs: MacAddressBlock, ) -> Result<(), RequestError> { - Self::set_once(&mut self.mac_address_block, macs).map_err(Into::into) + Self::set_once(self.mac_address_block, macs).map_err(Into::into) } fn get_identity( @@ -177,7 +177,7 @@ impl idl::InOrderPackratImpl for ServerImpl { _: &RecvMessage, identity: VpdIdentity, ) -> Result<(), RequestError> { - Self::set_once(&mut self.identity, identity).map_err(Into::into) + Self::set_once(self.identity, identity).map_err(Into::into) } #[cfg(feature = "gimlet")] diff --git a/task/power/src/main.rs b/task/power/src/main.rs index 8f612a88d..60e8272d5 100644 --- a/task/power/src/main.rs +++ b/task/power/src/main.rs @@ -802,7 +802,7 @@ impl idl::InOrderPowerImpl for ServerImpl { if phase < phases.len() { return match dev.read_phase_current(Phase(phases[phase])) { - Err(e) => Err(ResponseCode::from(e).into()), + Err(e) => Err(e.into()), Ok(val) => Ok(val.0), }; } diff --git a/task/sensor/src/main.rs b/task/sensor/src/main.rs index b056c0649..7d076b33c 100644 --- a/task/sensor/src/main.rs +++ b/task/sensor/src/main.rs @@ -201,7 +201,7 @@ impl idl::InOrderSensorImpl for ServerImpl { self.nerrors .get(id) .cloned() - .ok_or(SensorApiError::InvalidSensor.into()) + .ok_or_else(|| SensorApiError::InvalidSensor.into()) } } diff --git a/task/sp_measure/build.rs b/task/sp_measure/build.rs index 3df391224..3319770a6 100644 --- a/task/sp_measure/build.rs +++ b/task/sp_measure/build.rs @@ -17,7 +17,7 @@ const TEST_SIZE: usize = 0x0010_0000; fn main() -> Result<(), Box> { let out_dir = build_util::out_dir(); let dest_path = out_dir.join("expected.rs"); - let mut file = std::fs::File::create(&dest_path)?; + let mut file = std::fs::File::create(dest_path)?; let task_config = build_util::task_config::()?; diff --git a/task/sp_measure/src/main.rs b/task/sp_measure/src/main.rs index 70ccbd84d..d2bfdba9e 100644 --- a/task/sp_measure/src/main.rs +++ b/task/sp_measure/src/main.rs @@ -55,7 +55,7 @@ fn main() -> ! { panic!(); } - sha.update(&data); + sha.update(data); } let sha_out = sha.finalize(); diff --git a/task/thermal/src/control.rs b/task/thermal/src/control.rs index 1368dea04..dca5fce3b 100644 --- a/task/thermal/src/control.rs +++ b/task/thermal/src/control.rs @@ -89,13 +89,13 @@ pub struct Fans([Option; N]); impl core::ops::Index for Fans<{ bsp::NUM_FANS }> { type Output = Option; - fn index<'a>(&'a self, index: usize) -> &'a Option { + fn index(&self, index: usize) -> &Option { &self.0[index] } } impl core::ops::IndexMut for Fans<{ bsp::NUM_FANS }> { - fn index_mut<'a>(&'a mut self, index: usize) -> &'a mut Option { + fn index_mut(&mut self, index: usize) -> &mut Option { &mut self.0[index] } } @@ -1093,6 +1093,7 @@ impl<'a> ThermalControl<'a> { index: usize, model: ThermalProperties, ) -> Result<(), ThermalError> { + #[allow(clippy::absurd_extreme_comparisons)] if index >= bsp::NUM_DYNAMIC_TEMPERATURE_INPUTS { return Err(ThermalError::InvalidIndex); } @@ -1111,6 +1112,7 @@ impl<'a> ThermalControl<'a> { &mut self, index: usize, ) -> Result<(), ThermalError> { + #[allow(clippy::absurd_extreme_comparisons)] if index >= bsp::NUM_DYNAMIC_TEMPERATURE_INPUTS { Err(ThermalError::InvalidIndex) } else { diff --git a/task/uartecho/src/main.rs b/task/uartecho/src/main.rs index 9e8cca61f..801128b4f 100644 --- a/task/uartecho/src/main.rs +++ b/task/uartecho/src/main.rs @@ -72,9 +72,9 @@ fn main() -> ! { // transmit the first, and if we send all of it, try to // transmit the second. let (line_buf0, line_buf1) = line_buf.as_slices(); - let mut n = tx_until_fifo_full(&uart, &line_buf0); + let mut n = tx_until_fifo_full(&uart, line_buf0); if n == line_buf0.len() { - n += tx_until_fifo_full(&uart, &line_buf1); + n += tx_until_fifo_full(&uart, line_buf1); } // Remove all the data we sent from our buffer. @@ -190,10 +190,6 @@ fn configure_uart_device() -> Usart { let hardware_flow_control = cfg!(feature = "hardware_flow_control"); - let usart; - let peripheral; - let pins; - cfg_if::cfg_if! { if #[cfg(feature = "usart1")] { const PINS: &[(PinSet, Alternate)] = { @@ -216,9 +212,8 @@ fn configure_uart_device() -> Usart { // essentially a static, and we access it through a & reference so // aliasing is not a concern. Were it literally a static, we could // just reference it. - usart = unsafe { &*device::USART1::ptr() }; - peripheral = Peripheral::Usart1; - pins = PINS; + let usart = unsafe { &*device::USART1::ptr() }; + let peripheral = Peripheral::Usart1; } else if #[cfg(feature = "usart2")] { const PINS: &[(PinSet, Alternate)] = { if cfg!(feature = "hardware_flow_control") { @@ -230,9 +225,8 @@ fn configure_uart_device() -> Usart { &[(Port::D.pin(5).and_pin(6), Alternate::AF7)] } }; - usart = unsafe { &*device::USART2::ptr() }; - peripheral = Peripheral::Usart2; - pins = PINS; + let usart = unsafe { &*device::USART2::ptr() }; + let peripheral = Peripheral::Usart2; } else if #[cfg(feature = "uart7")] { const PINS: &[(PinSet, Alternate)] = { if cfg!(feature = "hardware_flow_control") { @@ -244,9 +238,8 @@ fn configure_uart_device() -> Usart { &[(Port::E.pin(7).and_pin(8), Alternate::AF7)] } }; - usart = unsafe { &*device::UART7::ptr() }; - peripheral = Peripheral::Uart7; - pins = PINS; + let usart = unsafe { &*device::UART7::ptr() }; + let peripheral = Peripheral::Uart7; } else { compile_error!("no usartX/uartX feature specified"); } @@ -256,7 +249,7 @@ fn configure_uart_device() -> Usart { &Sys::from(SYS.get_task_id()), usart, peripheral, - pins, + PINS, CLOCK_HZ, BAUD_RATE, hardware_flow_control, diff --git a/task/udpbroadcast/src/main.rs b/task/udpbroadcast/src/main.rs index 6e3676fcd..be01c7a8b 100644 --- a/task/udpbroadcast/src/main.rs +++ b/task/udpbroadcast/src/main.rs @@ -103,7 +103,7 @@ fn main() -> ! { }; hl::sleep_for(500); - match net.send_packet(SOCKET, meta, &out[..]) { + match net.send_packet(SOCKET, meta, out) { Ok(()) => UDP_BROADCAST_COUNT .fetch_add(1, core::sync::atomic::Ordering::Relaxed), Err(_) => UDP_ERROR_COUNT