Skip to content

Commit

Permalink
Merge pull request torvalds#346 from TheSven73/rust-for-linux-no-ifdefs
Browse files Browse the repository at this point in the history
rust/kernel: remove config `#ifdef` in Error.rs file
  • Loading branch information
ojeda committed Jun 4, 2021
2 parents cae4454 + 40676ff commit f9dc4fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
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

0 comments on commit f9dc4fc

Please sign in to comment.