Skip to contentSkip to conversation

rust: uaccess: take advantage of the prelude and `Result`'s defaults

PATCH Applied Miguel Ojeda 3 participants 3 messages Apr 29, 2025 – May 12, 2025 Rust

lore
Share & tools
lore

Miguel Ojeda

author maintainer
#0 lore raw

PATCH 1/1 rust: uaccess: take advantage of the prelude and `Result`'s defaults

The kernel prelude brings Result and the error codes; and the prelude itself is already available in the examples automatically.

In addition, Result already defaults to T = ().

Thus simplify.

---
A quick thing I noticed looking at something else...

 rust/kernel/uaccess.rs | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
rust/kernel/uaccess.rs +1 -3
index 80a9782b1c6e..7e4c953ba8a1 100644
@@ -46,10 +46,9 @@
 ///
 /// ```no_run
 /// use kernel::ffi::c_void;
-/// use kernel::error::Result;
 /// use kernel::uaccess::{UserPtr, UserSlice};
 ///
-/// fn bytes_add_one(uptr: UserPtr, len: usize) -> Result<()> {
+/// fn bytes_add_one(uptr: UserPtr, len: usize) -> Result {
 ///     let (read, mut write) = UserSlice::new(uptr, len).reader_writer();
 ///
 ///     let mut buf = KVec::new();
@@ -68,7 +67,6 @@
 ///
 /// ```no_run
 /// use kernel::ffi::c_void;
-/// use kernel::error::{code::EINVAL, Result};
 /// use kernel::uaccess::{UserPtr, UserSlice};
 ///
 /// /// Returns whether the data in this region is valid.

base-commit: b4432656b36e5cc1d50a1f2dc15357543add530e --
2.49.0

Applied
#2 lore raw
In reply to Miguel Ojeda
Quoted 9 lines · Miguel Ojeda

The kernel prelude brings Result and the error codes; and the prelude itself is already available in the examples automatically.

In addition, Result already defaults to T = ().

Thus simplify.

Applied to rust-next -- thanks!

Cheers,
Miguel