Skip to content
Closed
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
13 changes: 4 additions & 9 deletions rust/kernel/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,16 @@ impl Error {

/// Creates an [`Error`] from a kernel error code.
///
/// It is a bug to pass an out-of-range `errno`. `EINVAL` would
/// It is a bug to pass an out-of-range `errno`. Err(`EINVAL`) would
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// It is a bug to pass an out-of-range `errno`. Err(`EINVAL`) would
/// It is a bug to pass an out-of-range `errno`. `Err(EINVAL)` would

/// be returned in such a case.
pub(crate) fn from_kernel_errno(errno: c_types::c_int) -> Error {
pub(crate) fn from_kernel_errno(errno: c_types::c_int) -> Result<Error> {
if errno < -(bindings::MAX_ERRNO as i32) || errno >= 0 {
// TODO: make it a `WARN_ONCE` once available.
crate::pr_warn!(
"attempted to create `Error` with out of range `errno`: {}",
errno
);
return Error::EINVAL;
return Err(Error::EINVAL);
}

// INVARIANT: the check above ensures the type invariant
// will hold.
Error(errno)
Ok(Error(errno))
}

/// Creates an [`Error`] from a kernel error code.
Expand Down