]> git.ipfire.org Git - thirdparty/linux.git/commit
rust: time: fix as_micros_ceil() to round correctly for negative Delta
authorFUJITA Tomonori <fujita.tomonori@gmail.com>
Mon, 13 Jul 2026 22:52:35 +0000 (07:52 +0900)
committerMiguel Ojeda <ojeda@kernel.org>
Sat, 18 Jul 2026 17:07:35 +0000 (19:07 +0200)
commit880c43b185ca52239e75bc546cc4f4d9154d0fed
tree8f4d0d4e27a07b3a0a5cae86e1d48dab9a135443
parenta19bda861b3a79e25417462539df8b0d77c6b322
rust: time: fix as_micros_ceil() to round correctly for negative Delta

The ceiling-division idiom `(n + d - 1) / d` only produces the
correct result when `n` is non-negative.

For example, if n = -1000 (exactly -1us), the old code computed (-1000
+ 999) / 1000 == 0 instead of -1.

For negative n, truncating division already rounds towards positive
infinity, so no bias is needed in that case.

Fixes: fae0cdc12340 ("rust: time: Introduce Delta type")
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Acked-by: Andreas Hindborg <a.hindborg@kernel.org>
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20260713225235.3243480-1-tomo@flapping.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/time.rs