[PATCH 2/7] rust: add warn_on_err macro

From: Alexandre Courbot

Date: Tue Dec 16 2025 - 00:16:12 EST


While we already have the `warn_on` macro, a common usage patterns in
Rust is to check whether a `Result` is an error. Add a helper macro that
allows this.

Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
---
rust/kernel/bug.rs | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/rust/kernel/bug.rs b/rust/kernel/bug.rs
index 36aef43e5ebe..255c780bb4f7 100644
--- a/rust/kernel/bug.rs
+++ b/rust/kernel/bug.rs
@@ -124,3 +124,13 @@ macro_rules! warn_on {
cond
}};
}
+
+/// Report a warning if `res` is an error and return it unmodified.
+#[macro_export]
+macro_rules! warn_on_err {
+ ($res:expr) => {{
+ let res = $res;
+ let _ = $crate::warn_on!(res.is_err());
+ res
+ }};
+}

--
2.52.0