From: Finn Behrens Date: Thu, 10 Nov 2022 16:41:20 +0000 (+0100) Subject: rust: error: declare errors using macro X-Git-Tag: v6.6.7~3980^2~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4b0c68bd0d8b0e23ab1763d4a6632720dd3f1a83;p=platform%2Fkernel%2Flinux-starfive.git rust: error: declare errors using macro Add a macro to declare errors, which simplifies the work needed to add each one, avoids repetition of the code and makes it easier to change the way they are declared. Signed-off-by: Finn Behrens Reviewed-by: Gary Guo [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda --- diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs index 466b2a8..b843f34 100644 --- a/rust/kernel/error.rs +++ b/rust/kernel/error.rs @@ -8,8 +8,16 @@ use alloc::collections::TryReserveError; /// Contains the C-compatible error codes. pub mod code { - /// Out of memory. - pub const ENOMEM: super::Error = super::Error(-(crate::bindings::ENOMEM as i32)); + macro_rules! declare_err { + ($err:tt $(,)? $($doc:expr),+) => { + $( + #[doc = $doc] + )* + pub const $err: super::Error = super::Error(-(crate::bindings::$err as i32)); + }; + } + + declare_err!(ENOMEM, "Out of memory."); } /// Generic integer kernel error.