Re: [PATCH 1/2] rust: add functions and traits for lossless integer conversions

Miguel Ojeda <[email protected]> Mon, 27 Jul 2026 13:10:54 +0200
Newsgroups dev.linux.lists.nova-gpu,org.kernel.vger.linux-kernel,org.kernel.vger.rust-for-linux
Message-ID <CANiq72nwo=NSCOaafPc_4beonpJO3x6Njj-GKcW7q3Hk8P80yA@mail.gmail.com>
On Mon, Jul 27, 2026 at 12:28=E2=80=AFPM Gary Guo <[email protected]> wrote:
>
> I'm okay with having u32 -> usize casts and usize -> u64 casts, but havin=
g
> usize -> u32 and u64 -> usize casts like this series do is worrying as it=
 can be
> misused from drivers that are supposed to be supporting multiple platform=
s or
> core subsystems.
>
> Pointer-size dependent drivers that need these casts should define them l=
ocally.

Ideally we would define it once, but nevertheless make it explicit
enough (somehow) that this makes one not build in certain configs, so
that we get no repetition and no confusion.

Something like splitting the non-portable ones into a different
trait/`mod`/method name/... so that it is very clear that it makes you
(i.e. the user) user pointer-size dependent just by e.g. `grep`ing for
it.

Cheers,
Miguel