Re: [PATCH v2 1/5] rust: add warn_on_err macro

Eliot Courtney
2026-04-21T07:07:58Z

On Tue Apr 21, 2026 at 3:16 PM JST, Alexandre Courbot wrote:
> While we already have the `warn_on` macro, a common usage pattern in
> Rust is to check whether a `Result` is an error. Add a helper macro that
> allows this.
>
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> ---
> rust/kernel/bug.rs | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/rust/kernel/bug.rs b/rust/kernel/bug.rs
> index ed943960f851..2fefc0aeef81 100644
> --- a/rust/kernel/bug.rs
> +++ b/rust/kernel/bug.rs
> @@ -130,3 +130,13 @@ macro_rules! warn_on {
> cond
> }};
> }
> +
> +/// Report a warning if `res` is an error and return it unmodified.

nit: "it" -> "the [`Result`] `res`" since it somewhat reads like it's
returning the error

Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>

> +#[macro_export]
> +macro_rules! warn_on_err {
> + ($res:expr) => {{
> + let res = $res;
> + let _ = $crate::warn_on!(res.is_err());
> + res
> + }};
> +}