Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust/kernel: remove config #ifdef in Error.rs file #346

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions rust/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <linux/gfp.h>
#include <linux/highmem.h>
#include <linux/uio.h>
#include <linux/errname.h>

void rust_helper_BUG(void)
{
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions rust/kernel/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down