Skip to content

Commit

Permalink
Rust: from_kernel_err_ptr() uses from_kernel_errno_unchecked()
Browse files Browse the repository at this point in the history
rust_helper_is_err() ensures err is a valid errno, we don't
need to check it again.

Signed-off-by: Fox Chen <[email protected]>
  • Loading branch information
foxhlchen committed Jun 2, 2021
1 parent a8bf6ef commit 00145c5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rust/kernel/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ pub(crate) fn from_kernel_err_ptr<T>(ptr: *mut T) -> Result<*mut T> {
// which always fits in an `i16`, as per the invariant above.
// And an `i16` always fits in an `i32`. So casting `err` to
// an `i32` can never overflow, and is always valid.
return Err(Error::from_kernel_errno(err as i32));
//
// INVARIANT: `rust_helper_is_err()` ensures `err` is a
// negative value greater-or-equal to `-bindings::MAX_ERRNO`
return Err(unsafe { Error::from_kernel_errno_unchecked(err as i32) });
}
Ok(ptr)
}

0 comments on commit 00145c5

Please sign in to comment.