Re: [PATCH v5 2/3] rust: time: make Delta division and remainder fail consistently

From: FUJITA Tomonori

Date: Sat Oct 31 2026 - 07:45:35 EST


On Sat, 31 Oct 2026 18:32:05 +0800
chenhan <chenhan0017.work@xxxxxxxxx> wrote:

> Delta's division and rem_nanos() use Rust operators on 64-bit and C
> helpers on 32-bit. The report shows that rem_nanos(0) can return 10 for
> a 10 ns dividend on ARMv7, while the same call panics on x86-64. The
> i64::MIN / -1 case also differs, and neither API documents these inputs.
>
> Check for zero divisors and i64::MIN with -1 before the architecture-
> specific code, and document the panic conditions on each method. This
> matches Rust's signed division and remainder operators, including when
> overflow checks are disabled. Valid-input results and API signatures
> are unchanged; invalid inputs now panic on 32-bit too.
>
> No in-tree calls to either API were found at the base commit. The checks
> stay in the existing methods so the fix does not depend on introducing
> a math module.
>
> Fixes: 4521438fb076 ("rust: time: Implement basic arithmetic operations for Delta")
> Reported-by: Georgios Androutsopoulos <georgeandrout13@xxxxxxxxx>
> Closes: https://github.com/Rust-for-Linux/linux/issues/1254
> Cc: stable@xxxxxxxxxxxxxxx
> Assisted-by: LLM
> Signed-off-by: chenhan <chenhan0017.work@xxxxxxxxx>

Reviewed-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxx>