From 87041ea98af9494818485f38c1dab466d96432fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20L=C3=B3pez?= Date: Fri, 22 Nov 2024 17:04:52 +0100 Subject: [PATCH 1/4] acpi: remove needless lifetimes Running clippy on the ACPI crate returns several warnings about unneeded lifetimes, so remove them. --- acpi/src/lib.rs | 4 ++-- acpi/src/managed_slice.rs | 10 +++++----- acpi/src/platform/mod.rs | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/acpi/src/lib.rs b/acpi/src/lib.rs index f59cef00..b73966da 100644 --- a/acpi/src/lib.rs +++ b/acpi/src/lib.rs @@ -431,7 +431,7 @@ where handler: H, } -impl<'t, H> Iterator for SsdtIterator<'t, H> +impl Iterator for SsdtIterator<'_, H> where H: AcpiHandler, { @@ -479,7 +479,7 @@ where handler: H, } -impl<'t, H> Iterator for SdtHeaderIterator<'t, H> +impl Iterator for SdtHeaderIterator<'_, H> where H: AcpiHandler, { diff --git a/acpi/src/managed_slice.rs b/acpi/src/managed_slice.rs index e00c9c80..a46c514f 100644 --- a/acpi/src/managed_slice.rs +++ b/acpi/src/managed_slice.rs @@ -16,7 +16,7 @@ where allocator: A, } -impl<'a, T, A> ManagedSlice<'a, T, A> +impl ManagedSlice<'_, T, A> where A: Allocator, { @@ -34,13 +34,13 @@ where } #[cfg(feature = "alloc")] -impl<'a, T> ManagedSlice<'a, T, alloc::alloc::Global> { +impl ManagedSlice<'_, T, alloc::alloc::Global> { pub fn new(len: usize) -> AcpiResult { Self::new_in(len, alloc::alloc::Global) } } -impl<'a, T, A> Drop for ManagedSlice<'a, T, A> +impl Drop for ManagedSlice<'_, T, A> where A: Allocator, { @@ -54,7 +54,7 @@ where } } -impl<'a, T, A> core::ops::Deref for ManagedSlice<'a, T, A> +impl core::ops::Deref for ManagedSlice<'_, T, A> where A: Allocator, { @@ -65,7 +65,7 @@ where } } -impl<'a, T, A> core::ops::DerefMut for ManagedSlice<'a, T, A> +impl core::ops::DerefMut for ManagedSlice<'_, T, A> where A: Allocator, { diff --git a/acpi/src/platform/mod.rs b/acpi/src/platform/mod.rs index f1239bf3..c3b29cf5 100644 --- a/acpi/src/platform/mod.rs +++ b/acpi/src/platform/mod.rs @@ -102,7 +102,7 @@ where } #[cfg(feature = "alloc")] -impl<'a> PlatformInfo<'a, alloc::alloc::Global> { +impl PlatformInfo<'_, alloc::alloc::Global> { pub fn new(tables: &AcpiTables) -> AcpiResult where H: AcpiHandler, @@ -111,7 +111,7 @@ impl<'a> PlatformInfo<'a, alloc::alloc::Global> { } } -impl<'a, A> PlatformInfo<'a, A> +impl PlatformInfo<'_, A> where A: Allocator + Clone, { From e158098d2ec7b9a2c7e7ac416418e88889ff6b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20L=C3=B3pez?= Date: Fri, 22 Nov 2024 17:08:24 +0100 Subject: [PATCH 2/4] acpi: fix misc clippy warnings --- acpi/src/lib.rs | 2 +- acpi/src/madt.rs | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/acpi/src/lib.rs b/acpi/src/lib.rs index b73966da..4278161e 100644 --- a/acpi/src/lib.rs +++ b/acpi/src/lib.rs @@ -28,7 +28,7 @@ //! * Use `AcpiTables::from_rsdp` if you have the physical address of the RSDP //! * Use `AcpiTables::from_rsdt` if you have the physical address of the RSDT/XSDT //! * Use `AcpiTables::search_for_rsdp_bios` if you don't have the address of either, but **you know you are -//! running on BIOS, not UEFI** +//! running on BIOS, not UEFI** //! //! `AcpiTables` stores the addresses of all of the tables detected on a platform. The SDTs are parsed by this //! library, or can be accessed directly with `from_sdt`, while the `DSDT` and any `SSDTs` should be parsed with diff --git a/acpi/src/madt.rs b/acpi/src/madt.rs index e9b0192a..8424e893 100644 --- a/acpi/src/madt.rs +++ b/acpi/src/madt.rs @@ -53,11 +53,8 @@ unsafe impl AcpiTable for Madt { impl Madt { pub fn get_mpwk_mailbox_addr(&self) -> Result { for entry in self.entries() { - match entry { - MadtEntry::MultiprocessorWakeup(entry) => { - return Ok(entry.mailbox_address); - } - _ => {} + if let MadtEntry::MultiprocessorWakeup(entry) = entry { + return Ok(entry.mailbox_address); } } Err(AcpiError::InvalidMadt(MadtError::UnexpectedEntry)) From bdaa8704103ed55de74c3cc2dd23d365223a89ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20L=C3=B3pez?= Date: Fri, 22 Nov 2024 17:14:40 +0100 Subject: [PATCH 3/4] acpi: fix safety docs Place safety documentation in a separate section so that clippy does not emit a warning for them. Add any missing safety documentation as well. --- acpi/src/handler.rs | 4 ++++ acpi/src/lib.rs | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/acpi/src/handler.rs b/acpi/src/handler.rs index b3d9286c..46a65328 100644 --- a/acpi/src/handler.rs +++ b/acpi/src/handler.rs @@ -51,6 +51,10 @@ where /// than `region_length`, due to requirements of the paging system or other reasoning. /// - `handler` should be the same `AcpiHandler` that created the mapping. When the `PhysicalMapping` is /// dropped, it will be used to unmap the structure. + /// + /// ### Safety + /// + /// The caller must ensure that the physical memory can be safely mapped. pub unsafe fn new( physical_start: usize, virtual_start: NonNull, diff --git a/acpi/src/lib.rs b/acpi/src/lib.rs index 4278161e..5ec29024 100644 --- a/acpi/src/lib.rs +++ b/acpi/src/lib.rs @@ -200,7 +200,9 @@ where { /// Create an `AcpiTables` if you have the physical address of the RSDP. /// - /// ### Safety: Caller must ensure the provided address is valid to read as an RSDP. + /// ### Safety + /// + /// Caller must ensure the provided address is valid to read as an RSDP. pub unsafe fn from_rsdp(handler: H, address: usize) -> AcpiResult { let rsdp_mapping = unsafe { handler.map_physical_region::(address, mem::size_of::()) }; rsdp_mapping.validate()?; @@ -212,6 +214,10 @@ where /// Search for the RSDP on a BIOS platform. This accesses BIOS-specific memory locations and will probably not /// work on UEFI platforms. See [Rsdp::search_for_rsdp_bios](rsdp_search::Rsdp::search_for_rsdp_bios) for /// details. + /// + /// ### Safety + /// + /// The caller must ensure that this function is called on BIOS platforms. pub unsafe fn search_for_rsdp_bios(handler: H) -> AcpiResult { let rsdp_mapping = unsafe { Rsdp::search_for_on_bios(handler.clone())? }; // Safety: RSDP has been validated from `Rsdp::search_for_on_bios` @@ -222,7 +228,9 @@ where /// from `from_rsdp` after validation, but can also be used if you've searched for the RSDP manually on a BIOS /// system. /// - /// ### Safety: Caller must ensure that the provided mapping is a fully validated RSDP. + /// ### Safety + /// + /// Caller must ensure that the provided mapping is a fully validated RSDP. pub unsafe fn from_validated_rsdp(handler: H, rsdp_mapping: PhysicalMapping) -> AcpiResult { let revision = rsdp_mapping.revision(); let root_table_mapping = if revision == 0 { @@ -247,7 +255,9 @@ where /// Create an `AcpiTables` if you have the physical address of the RSDT/XSDT. /// - /// ### Safety: Caller must ensure the provided address is valid RSDT/XSDT address. + /// ### Safety + /// + /// Caller must ensure the provided address is valid RSDT/XSDT address. pub unsafe fn from_rsdt(handler: H, revision: u8, address: usize) -> AcpiResult { let root_table_mapping = if revision == 0 { /* @@ -408,7 +418,9 @@ impl AmlTable { } } -/// ### Safety: Caller must ensure the provided address is valid for being read as an `SdtHeader`. +/// ### Safety +/// +/// Caller must ensure the provided address is valid for being read as an `SdtHeader`. unsafe fn read_table( handler: H, address: usize, From b3b0955061d47c8a22e77eef9b81c3d0ded1825b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20L=C3=B3pez?= Date: Fri, 22 Nov 2024 18:26:47 +0100 Subject: [PATCH 4/4] ci: run clippy on acpi crate Now that all warnings have been fixed for the acpi crate, run clippy as part of CI. Once the warnings for the rest of the crates are fixed, they can be included in the CI run. --- .github/workflows/build.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f622442e..b68e565b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,3 +64,20 @@ jobs: - name: Run AML test suite run: cargo run --bin aml_tester -- -p tests --reset + + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: 'recursive' + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + default: true + profile: minimal + components: clippy + + - name: Run clippy + run: cargo clippy -p acpi