Skip to content

Commit 1a238a2

Browse files
committed
clippy pedantic
1 parent c15a923 commit 1a238a2

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

flc-asm/src/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
unsafe_op_in_unsafe_fn,
1515
clippy::undocumented_unsafe_blocks
1616
)]
17+
#![allow(
18+
clippy::inline_always,
19+
reason = "we need the functions to be inlined in this specific case"
20+
)]
1721

1822
use core::{arch::asm, panic::PanicInfo, ptr::read_volatile};
1923

@@ -200,12 +204,14 @@ impl FlashController<'_, '_> {
200204
/// This MUST be called after any write/erase flash controller operations.
201205
#[inline(always)]
202206
fn flush_icc(&self) {
207+
const PAGE1: u32 = FLASH_MEM_BASE;
208+
const PAGE2: u32 = FLASH_MEM_BASE + FLASH_PAGE_SIZE;
209+
203210
self.gcr.sysctrl().modify(|_, w| w.icc0_flush().flush());
204211
while !self.gcr.sysctrl().read().icc0_flush().bit_is_clear() {}
205212

206213
// Clear the line fill buffer by reading 2 pages from flash
207-
const PAGE1: u32 = FLASH_MEM_BASE;
208-
const PAGE2: u32 = FLASH_MEM_BASE + FLASH_PAGE_SIZE;
214+
209215
// SAFETY: `FLASH_MEM_BASE` points to a valid, aligned word within flash space.
210216
const {
211217
assert!(check_address_bounds(PAGE1..PAGE1 + 4));
@@ -272,6 +278,10 @@ impl FlashController<'_, '_> {
272278
if likely(!check_address_bounds(address..address + 16)) {
273279
panic();
274280
}
281+
#[allow(
282+
clippy::cast_possible_truncation,
283+
reason = "the target pointer width is 32, so this will not truncate"
284+
)]
275285
if likely(address % size_of::<[u32; 4]>() as u32 != 0) {
276286
panic();
277287
}
@@ -310,6 +320,10 @@ impl FlashController<'_, '_> {
310320
/// contained in flash space.
311321
#[inline(always)]
312322
unsafe fn page_erase(&self, address: u32, sys_clk_freq: u32) {
323+
#[allow(
324+
clippy::range_plus_one,
325+
reason = "the caller takes a Range struct, not an `impl RangeBounds`"
326+
)]
313327
if likely(!check_address_bounds(address..address + 1)) {
314328
panic()
315329
}
@@ -382,7 +396,7 @@ pub unsafe extern "C" fn write128(address: *mut [u32; 4], data: *const u32, sys_
382396
};
383397

384398
// SAFETY: the caller must ensure that `data` points to a valid array of four `u32`s.
385-
let data = unsafe { &*(data as *const [u32; 4]) };
399+
let data = unsafe { &*data.cast() };
386400

387401
// SAFETY:
388402
// - the caller must guarantee that the address is aligned and the word is within flash space

0 commit comments

Comments
 (0)