[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAH5fLgggbF2KWHazQ9rDeyVEjxg4LipfXA1qepPAhkkaHD4Mxw@mail.gmail.com>
Date: Fri, 22 Aug 2025 09:46:15 +0200
From: Alice Ryhl <aliceryhl@...gle.com>
To: Lyude Paul <lyude@...hat.com>
Cc: Andreas Hindborg <a.hindborg@...nel.org>, Boqun Feng <boqun.feng@...il.com>,
FUJITA Tomonori <fujita.tomonori@...il.com>, Frederic Weisbecker <frederic@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>, Anna-Maria Behnsen <anna-maria@...utronix.de>,
John Stultz <jstultz@...gle.com>, Stephen Boyd <sboyd@...nel.org>, Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>, Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>,
"open list:DELAY, SLEEP, TIMEKEEPING, TIMERS [RUST]" <rust-for-linux@...r.kernel.org>, open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v9 6/7] rust: time: Add Instant::from_ktime()
On Thu, Aug 21, 2025 at 9:34 PM Lyude Paul <lyude@...hat.com> wrote:
>
> For implementing Rust bindings which can return a point in time.
>
> Signed-off-by: Lyude Paul <lyude@...hat.com>
Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
> V4:
> * Turn from_nanos() into an unsafe function in order to ensure that we
> uphold the invariants of Instant
> V5:
> * Add debug_assert!() to from_nanos
> V8:
> * Change name of function from Instant::from_nanos() to
> Instant::from_ktime()
> V9:
> * Fix outdated comments in from_ktime (nanos -> ktime)
>
> rust/kernel/time.rs | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
> index 64c8dcf548d63..874a1023dcdf9 100644
> --- a/rust/kernel/time.rs
> +++ b/rust/kernel/time.rs
> @@ -200,6 +200,29 @@ pub fn elapsed(&self) -> Delta {
> pub(crate) fn as_nanos(&self) -> i64 {
> self.inner
> }
> +
> + /// Create an [`Instant`] from a `ktime_t` without checking if it is non-negative.
> + ///
> + /// # Panics
> + ///
> + /// On debug builds, this function will panic if `ktime` is not in the range from 0 to
> + /// `KTIME_MAX`.
> + ///
> + /// # Safety
> + ///
> + /// The caller promises that `ktime` is in the range from 0 to `KTIME_MAX`.
> + #[expect(unused)]
I would consider just making it pub to avoid the need for this expect.
> + #[inline]
> + pub(crate) unsafe fn from_ktime(ktime: bindings::ktime_t) -> Self {
> + debug_assert!(ktime >= 0);
If you're going to have a debug assertion, perhaps it would make sense
to check both bounds?
Alice
Powered by blists - more mailing lists