Re: [PATCH v1] rust: time: fix as_micros_ceil() rounding near i64::MAX

Andreas Hindborg <[email protected]> Thu, 06 Aug 2026 10:58:47 +0200
Newsgroups org.kernel.vger.rust-for-linux
Message-ID <[email protected]>
"FUJITA Tomonori" <[email protected]> writes:

> On Wed, 05 Aug 2026 13:39:43 +0200
> Andreas Hindborg <[email protected]> wrote:
>
>> "FUJITA Tomonori" <[email protected]> writes:
>>
>>> From: FUJITA Tomonori <[email protected]>
>>>
>>> The ceiling adjustment used saturating_add(NSEC_PER_USEC - 1) before
>>> dividing. Once the nanosecond value gets within NSEC_PER_USEC - 1 of
>>> i64::MAX the addition saturates to i64::MAX, which drops the ceiling
>>> bias and yields a result one microsecond too small.
>>>
>>> Fixes: fae0cdc12340 ("rust: time: Introduce Delta type")
>>> Reported-by: Miguel Ojeda <[email protected]>
>>> Closes: https://lore.kernel.org/rust-for-linux/CANiq72mtS0ABA2JnT5tpz6J9c_mnxY+vyPvghV_ukngWvN8F2w@mail.gmail.com/
>>> Signed-off-by: FUJITA Tomonori <[email protected]>
>>
>> Reviewed-by: Andreas Hindborg <[email protected]>
>>
>> It took me a little while to understand this one. Perhaps a few comments
>> explaining the boundary conditions could be warranted here?
>
> I added the comments for as_millis_ceil() [1]. You want the similar
> comments for as_micros_ceil() too?
>
> Or we could add a small helper for _ceil() and keep the explanation in
> one place.

Let's add the comment to this one, as it will go in with rust tree fixes
asap. Then you can extract to reduce duplication in your other series.
Ok with you?


Best regards,
Andreas Hindborg