From 7926ab9e5edef9f06ca2c4270cec685b26f5c39f Mon Sep 17 00:00:00 2001 From: Julian Stecklina Date: Mon, 28 Nov 2022 13:38:01 +0100 Subject: [PATCH] lanzaboote: fix clippy issues --- rust/lanzaboote/src/linux_loader.rs | 8 ++++---- rust/lanzaboote/src/pe_section.rs | 9 +++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/rust/lanzaboote/src/linux_loader.rs b/rust/lanzaboote/src/linux_loader.rs index 95f9922..46857ad 100644 --- a/rust/lanzaboote/src/linux_loader.rs +++ b/rust/lanzaboote/src/linux_loader.rs @@ -147,16 +147,16 @@ fn initrd_location(initrd_efi: &mut RegularFile) -> Result> { .sections .iter() .find(|s| s.name().unwrap() == ".initrd") - .and_then(|s| { + .map(|s| { let section_start: usize = s.pointer_to_raw_data.try_into().unwrap(); let section_size: usize = s.size_of_raw_data.try_into().unwrap(); - Some(Range { + Range { start: section_start, end: section_start + section_size, - }) + } }) - .ok_or(Status::END_OF_FILE.into()) + .ok_or_else(|| Status::END_OF_FILE.into()) } /// Check the signature of the initrd. diff --git a/rust/lanzaboote/src/pe_section.rs b/rust/lanzaboote/src/pe_section.rs index 4b6d178..0ef7cce 100644 --- a/rust/lanzaboote/src/pe_section.rs +++ b/rust/lanzaboote/src/pe_section.rs @@ -1,3 +1,9 @@ +// Clippy doesn't like the lifetimes, but rustc wants them. 🤷 +#![allow(clippy::needless_lifetimes)] +// Clippy doesn't understand that we exit with ? from the closure in +// and_then below and this can't be expressed with map. +#![allow(clippy::bind_instead_of_map)] + use alloc::{borrow::ToOwned, string::String}; /// Extracts the data of a section of a PE file. @@ -20,6 +26,5 @@ pub fn pe_section<'a>(file_data: &'a [u8], section_name: &str) -> Option<&'a [u8 /// Extracts the data of a section of a PE file and returns it as a string. pub fn pe_section_as_string<'a>(file_data: &'a [u8], section_name: &str) -> Option { - pe_section(file_data, section_name) - .and_then(|data| Some(core::str::from_utf8(data).unwrap().to_owned())) + pe_section(file_data, section_name).map(|data| core::str::from_utf8(data).unwrap().to_owned()) }