lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <87qztw26bf.fsf@metaspace.dk>
Date: Mon, 17 Nov 2025 13:26:44 +0100
From: Andreas Hindborg <a.hindborg@...nel.org>
To: FUJITA Tomonori <fujita.tomonori@...il.com>
Cc: fujita.tomonori@...il.com, lyude@...hat.com,
 rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
 boqun.feng@...il.com, frederic@...nel.org, tglx@...utronix.de,
 anna-maria@...utronix.de, jstultz@...gle.com, sboyd@...nel.org,
 ojeda@...nel.org, alex.gaynor@...il.com, gary@...yguo.net,
 bjorn3_gh@...tonmail.com, lossin@...nel.org, aliceryhl@...gle.com,
 tmgross@...ch.edu, dakr@...nel.org
Subject: Re: [PATCH] rust/time: Add Delta::from_nanos()

"FUJITA Tomonori" <fujita.tomonori@...il.com> writes:

> On Mon, 17 Nov 2025 12:15:53 +0100
> Andreas Hindborg <a.hindborg@...nel.org> wrote:
>
>>>> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
>>>> index 6ea98dfcd0278..2b096e5a61cda 100644
>>>> --- a/rust/kernel/time.rs
>>>> +++ b/rust/kernel/time.rs
>>>> @@ -363,6 +363,12 @@ impl Delta {
>>>>      /// A span of time equal to zero.
>>>>      pub const ZERO: Self = Self { nanos: 0 };
>>>>
>>>> +    /// Create a new [`Delta`] from a number of nanoseconds.
>>>> +    #[inline]
>>>> +    pub const fn from_nanos(nanos: i64) -> Self {
>>>> +        Self { nanos }
>>>> +    }
>>>> +
>>>>      /// Create a new [`Delta`] from a number of microseconds.
>>>>      ///
>>>>      /// The `micros` can range from -9_223_372_036_854_775 to 9_223_372_036_854_775.
>>>
>>> For consistency with the other methods, perhaps we should also mention
>>> the valid nanos range in the comment?
>>
>> But, please make it a constant instead of an integer literal.
>
> Do you mean making the comment of Delta's from_* methods like the
> following?
>
> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
> index 6ea98dfcd027..822746e552fb 100644
> --- a/rust/kernel/time.rs
> +++ b/rust/kernel/time.rs
> @@ -363,9 +363,14 @@ impl Delta {
>      /// A span of time equal to zero.
>      pub const ZERO: Self = Self { nanos: 0 };
>
> +    /// The minimum number of microseconds that can be represented by a [`Delta`].
> +    pub const MIN_MICROS: i64 = -9_223_372_036_854_775;
> +    /// The maximum number of microseconds that can be represented by a [`Delta`].
> +    pub const MAX_MICROS: i64 = 9_223_372_036_854_775;
> +
>      /// Create a new [`Delta`] from a number of microseconds.
>      ///
> -    /// The `micros` can range from -9_223_372_036_854_775 to 9_223_372_036_854_775.
> +    /// The `micros` can range from [`Delta::MIN_MICROS`] to [`Delta::MAX_MICROS`].
>      /// If `micros` is outside this range, `i64::MIN` is used for negative values,
>      /// and `i64::MAX` is used for positive values due to saturation.
>      #[inline]

Yes, I would prefer that. The numbers become much more useful like this.


Best regards,
Andreas Hindborg



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ