Re: [PATCH net-next v2 2/6] rust: time: Introduce Delta type

From: Miguel Ojeda
Date: Sat Oct 05 2024 - 14:16:56 EST


On Sat, Oct 5, 2024 at 8:03 PM Andrew Lunn <andrew@xxxxxxx> wrote:
>
> But why limit it to u16, when the base value is a 63 bits? 65535 nS is
> not very long.

Agreed, for these constructors we should use (at the very least) the
biggest possible type that fits without possible wrapping.

> Dumb question. What does Rust in the kernel do if there is an
> overflow?

It is controlled by `CONFIG_RUST_OVERFLOW_CHECKS` -- it defaults to a
Rust panic, but otherwise it wraps. Either way, it is not UB and
regardless of the setting, it is considered a bug to be fixed.

(I requested upstream Rust a third mode that would allow us to report
the issue (e.g. map it to `WARN_ONCE`) and then continue with wrap.)

Cheers,
Miguel