Re: [PATCH v3 3/3] rust: math: add signed division and remainder helpers
From: chenhan
Date: Fri Oct 23 2026 - 09:06:58 EST
Hi Tomonori,
Thanks for the review and the follow-up suggestions.
I've sent v4 here:
https://lore.kernel.org/rust-for-linux/20261023130413.178487-1-chenhan0017.work@xxxxxxxxx/
> //! C header: [`include/linux/math64.h`](srctree/include/linux/math64.h).
Added the module-level link and checked its generated rustdoc target.
> How about matching the C function? Something like:
>
> pub fn div_s64_rem(dividend: i64, divisor: i32) -> (i64, i32)
V4 uses this interface. The 32-bit path returns both the C helper's
quotient and remainder. The 64-bit path uses Rust's signed operators,
with a comment explaining why the remainder fits in i32. The
documentation specifies the tuple order, truncation towards zero and
the remainder's sign.
Delta::rem_nanos() takes the remainder and converts it to i64, preserving
its public signature and panic conditions. div64_s64() remains available
for full-width divisors. Both helpers still reject zero and MIN/-1
regardless of the overflow-check setting.
The updated validation module calls both public helpers directly, checks
both tuple elements, and retains the Delta regression cases. It includes
i64::MIN divided by i32::MIN, whose quotient is 4294967296.
I have carried your Reviewed-by on patch 1. Since patch 3 now changes the
public interface, I have left its v3 Reviewed-by out of this revision and
noted why below the commit message. Could you confirm whether it also
applies to the updated patch?
Best regards,
chenhan