Re: [PATCH v1 1/2] rust: Add support for calling a function exactly once

Alice Ryhl
2025-11-05T10:35:40Z

On Wed, Nov 5, 2025 at 10:21 AM Onur Özkan <work@onurozkan.dev> wrote:
>
> On Wed, 5 Nov 2025 14:47:30 +0900
> FUJITA Tomonori <fujita.tomonori@gmail.com> wrote:
>
> > Add the Rust equivalent of the kernel's `DO_ONCE_LITE` macro. While it
> > would be possible to implement the feature entirely as a Rust macro,
> > the functionality that can be implemented as regular functions has
> > been extracted and implemented as the `OnceLite` struct for better
> > code maintainability.
> >
> > Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
> > ---
> > rust/kernel/lib.rs | 1 +
> > rust/kernel/once_lite.rs | 71
> > ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72
> > insertions(+) create mode 100644 rust/kernel/once_lite.rs
> >
> > diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
> > index 3dd7bebe7888..19553eb8c188 100644
> > --- a/rust/kernel/lib.rs
> > +++ b/rust/kernel/lib.rs
> > @@ -110,6 +110,7 @@
> > #[cfg(CONFIG_NET)]
> > pub mod net;
> > pub mod of;
> > +pub mod once_lite;
> > #[cfg(CONFIG_PM_OPP)]
> > pub mod opp;
> > pub mod page;
> > diff --git a/rust/kernel/once_lite.rs b/rust/kernel/once_lite.rs
> > new file mode 100644
> > index 000000000000..44ad5dbdc67e
> > --- /dev/null
> > +++ b/rust/kernel/once_lite.rs
> > @@ -0,0 +1,71 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +//! Support for calling a function exactly once.
> > +//!
> > +//! C header:
> > [`include/linux/once_lite.h`](srctree/include/linux/once_lite.h) +
>
> This seems like a pure Rust implementation. What exactly do we need
> from the "once_lite.h" in this module?

It's just a documentation link. I don't think it hurts for the Rust
impl to link to the equivalent C feature.

Alice