diff --git a/rust/helpers.c b/rust/helpers.c index 8c4541091a15ae..3526129f41c79a 100644 --- a/rust/helpers.c +++ b/rust/helpers.c @@ -7,6 +7,7 @@ #include #include #include +#include void rust_helper_BUG(void) { @@ -117,6 +118,11 @@ long rust_helper_ptr_err(__force const void *ptr) } EXPORT_SYMBOL_GPL(rust_helper_ptr_err); +const char *rust_helper_errname(int err) +{ + return errname(err); +} + /* We use bindgen's --size_t-is-usize option to bind the C size_t type * as the Rust usize type, so we can use it in contexts where Rust * expects a usize like slice (array) indices. usize is defined to be diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs index 6ac8630c8fb203..6841adaa31beb6 100644 --- a/rust/kernel/error.rs +++ b/rust/kernel/error.rs @@ -98,11 +98,11 @@ impl Error { impl fmt::Debug for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + extern "C" { + fn rust_helper_errname(err: c_types::c_int) -> *const c_types::c_char; + } // SAFETY: FFI call. - #[cfg(CONFIG_SYMBOLIC_ERRNAME)] - let name = unsafe { crate::bindings::errname(-self.0) }; - #[cfg(not(CONFIG_SYMBOLIC_ERRNAME))] - let name: *const c_types::c_char = core::ptr::null(); + let name = unsafe { rust_helper_errname(-self.0) }; if name.is_null() { // Print out number if no name can be found.