Skip to content

Commit 710bf7d

Browse files
committed
Rust: from_kernel_err_ptr() uses from_kernel_errno_unchecked()
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]>
1 parent a5b967c commit 710bf7d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

rust/kernel/error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,10 @@ pub(crate) fn from_kernel_err_ptr<T>(ptr: *mut T) -> Result<*mut T> {
256256
// which always fits in an `i16`, as per the invariant above.
257257
// And an `i16` always fits in an `i32`. So casting `err` to
258258
// an `i32` can never overflow, and is always valid.
259-
return Err(Error::from_kernel_errno(err as i32));
259+
//
260+
// INVARIANT: `rust_helper_is_err()` ensures `err` is a
261+
// negative value greater-or-equal to `-bindings::MAX_ERRNO`
262+
return Err(unsafe { Error::from_kernel_errno_unchecked(err as i32) });
260263
}
261264
Ok(ptr)
262265
}

0 commit comments

Comments
 (0)