Re: [PATCH v4 1/3] rust: Add `OnceLite` for executing code once

From: Andreas Hindborg
Date: Tue Feb 04 2025 - 06:11:27 EST


"Jens Korinth via B4 Relay" <devnull+jens.korinth.tuta.io@xxxxxxxxxx> writes:

> From: Jens Korinth <jens.korinth@xxxxxxx>
>
> Similar to `Once` in Rust's standard library, but with the same
> non-blocking behavior as the kernel's `DO_ONCE_LITE` macro. Abstraction
> allows easy replacement of the underlying sync mechanisms, see
>
> https://lore.kernel.org/rust-for-linux/20241109-pr_once_macros-v3-0-6beb24e0cac8@xxxxxxx/.
>
> Suggested-by: Boqun Feng <boqun.feng@xxxxxxxxx>
> Signed-off-by: Jens Korinth <jens.korinth@xxxxxxx>

Thanks for the patch!

I was using the series for `pr_warn_once!` elsewhere, and clippy gave me
this suggestion:

CLIPPY L rust/kernel.o
error: you should consider adding a `Default` implementation for `OnceLite`
--> /home/aeh/src/linux-rust/module-params/rust/kernel/once_lite.rs:52:5
|
52 | / pub const fn new() -> Self {
53 | | Self(AtomicBool::new(false), AtomicBool::new(false))
54 | | }
| |_____^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
= note: `-D clippy::new-without-default` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::new_without_default)]`
help: try adding this
|
49 + impl Default for OnceLite {
50 + fn default() -> Self {
51 + Self::new()
52 + }
53 + }
|



Best regards,
Andreas Hindborg