diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs index 5b5d108e05f44f..a5a8592fb34cad 100644 --- a/rust/kernel/error.rs +++ b/rust/kernel/error.rs @@ -256,7 +256,10 @@ pub(crate) fn from_kernel_err_ptr(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) }