Re: [PATCH v2 2/2] rust: cpu: use `unsafe_precondition_assert!`
From: Ritvik Gupta
Date: Thu May 21 2026 - 13:07:49 EST
On Tue, May 19, 2026 at 07:41:59AM +0200, Miguel Ojeda wrote:
> On Tue, May 19, 2026 at 12:57 AM Ritvik Gupta <ritvikfoss@xxxxxxxxx> wrote:
> >
> > Replace `debug_assert!` invocations with
> > `unsafe_precondition_assert!` in `from_i32_unchecked`
> > and `from_u32_unchecked` unsafe functions.
>
> The commit message doesn't mention why the messages were added -- I
> asked for it because I am not sure if it is worth providing a message
> for each assertion, especially since the original code decided to
> avoid it, i.e. the change to the new macro is good on its own,
> regardless of the messages.
>
Actually, I added messages from UX standpoint, as having explicit
failure reason is helpful for debugging, when an assertion is hit.
I can update the commit message to clarify this, or remove it if
maintainers prefer keeping it as is.
> > -use crate::{bindings, device::Device, error::Result, prelude::ENODEV};
> > +use crate::{bindings, device::Device, error::Result, prelude::*};
>
> By the way, we could remove `error::Result` from the list since we
> have the entire prelude now, and also take the chance to use the new
> style:
>
> https://docs.kernel.org/rust/coding-guidelines.html#imports
>
Sure, will remove `error::Result` and use vertical-import style.
> But maybe wait to see if the maintainers have other feedback before v3.
>
> Thanks!
>
> Cheers,
> Miguel
Yeah, will wait for some time.
Thanks for your feedback :)