[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CANiq72mstOhnZREwLoO5OR7JdnoFnQ-PDD7wQkJgjm-0A52DkA@mail.gmail.com>
Date: Fri, 22 Aug 2025 22:24:17 +0200
From: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
To: Onur Özkan <work@...rozkan.dev>
Cc: Alice Ryhl <aliceryhl@...gle.com>, rust-for-linux@...r.kernel.org, ojeda@...nel.org,
alex.gaynor@...il.com, boqun.feng@...il.com, gary@...yguo.net,
bjorn3_gh@...tonmail.com, lossin@...nel.org, a.hindborg@...nel.org,
tmgross@...ch.edu, dakr@...nel.org, tamird@...il.com,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] rust: uaccess: use to_result for error handling
On Fri, Aug 22, 2025 at 7:03 AM Onur Özkan <work@...rozkan.dev> wrote:
>
> Nice catch. I could use `try_into().unwrap_or(0)` but that feels a bit
> iffy since it would silently avoid the error if `isize` happens to be
> much smaller than what `i32` can handle (though I am not sure if it's
> possible in practice in the kernel codebase). Let's just ignore this
> patch.
`isize` is at least 32-bit, but I am not sure that would be more readable.
If we want to make all these cases go through a `to_result`-like
function, then we may want to have variants of that and so on instead
-- Onur created this related Zulip thread:
https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/returning.20.60Ok.28c_int.29.60.20instead.20of.20.60Ok.28.28.29.29.60.20on.20.60to_result.60/near/535616940
Similarly, we also may want to have a function or similar that allows
to perform such infallible casts (that are not infallible in general
Rust but are in the kernel); for reference, a similar recent
discussion at:
https://lore.kernel.org/rust-for-linux/CANiq72nW=XuUFqOB-6XavOPXtpbkHsagEkYvcD2JfCEiopYo=Q@mail.gmail.com/
Thanks!
Cheers,
Miguel
Powered by blists - more mailing lists