Skip to content

Commit c23f634

Browse files
author
Sven Van Asbroeck
committed
rust/kernel: remove redundant Error::from_kernel_errno()
It turns out that we don't need an `Error` constructor that checks the `errno` invariant at runtime. This is because we trust return values originating from kernel C. And any return values originating from Rust code can be constucted using `Error::` constants, which also do not need a runtime check: ```rust return Err(Error::EBUSY); ``` If we find we do require this function in the future, we may restore it simply by reverting this commit. Signed-off-by: Sven Van Asbroeck <[email protected]>
1 parent ed6fb94 commit c23f634

File tree

1 file changed

+0
-19
lines changed

1 file changed

+0
-19
lines changed

rust/kernel/error.rs

-19
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,6 @@ impl Error {
6060
/// Bad file number.
6161
pub const EBADF: Self = Error(-(bindings::EBADF as i32));
6262

63-
/// Creates an [`Error`] from a kernel error code.
64-
///
65-
/// It is a bug to pass an out-of-range `errno`. `EINVAL` would
66-
/// be returned in such a case.
67-
pub(crate) fn from_kernel_errno(errno: c_types::c_int) -> Error {
68-
if errno < -(bindings::MAX_ERRNO as i32) || errno >= 0 {
69-
// TODO: make it a `WARN_ONCE` once available.
70-
crate::pr_warn!(
71-
"attempted to create `Error` with out of range `errno`: {}",
72-
errno
73-
);
74-
return Error::EINVAL;
75-
}
76-
77-
// INVARIANT: the check above ensures the type invariant
78-
// will hold.
79-
Error(errno)
80-
}
81-
8263
/// Creates an [`Error`] from a kernel error code.
8364
///
8465
/// # Safety

0 commit comments

Comments
 (0)