Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: alloc: simplify with `NonNull::add()` now that it is stable

Currently, we need to go through raw pointers and then re-create the
`NonNull` from the result of offsetting the raw pointer.

`feature(non_null_convenience)` [1] has been stabilized in Rust
1.80.0 [2], which is older than our new minimum Rust version
(Rust 1.85.0).

Thus, now that we bump the Rust minimum version, simplify using
`NonNull::add()` and clean the TODO note.

Link: https://github.com/rust-lang/rust/issues/117691 [1]
Link: https://github.com/rust-lang/rust/pull/124498 [2]
Reviewed-by: Tamir Duberstein <tamird@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Link: https://patch.msgid.link/20260405235309.418950-15-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

+1 -7
+1 -7
rust/kernel/alloc/allocator/iter.rs
··· 42 42 return None; 43 43 } 44 44 45 - // TODO: Use `NonNull::add()` instead, once the minimum supported compiler version is 46 - // bumped to 1.80 or later. 47 - // 48 45 // SAFETY: `offset` is in the interval `[0, (self.page_count() - 1) * page::PAGE_SIZE]`, 49 46 // hence the resulting pointer is guaranteed to be within the same allocation. 50 - let ptr = unsafe { self.buf.as_ptr().add(offset) }; 51 - 52 - // SAFETY: `ptr` is guaranteed to be non-null given that it is derived from `self.buf`. 53 - let ptr = unsafe { NonNull::new_unchecked(ptr) }; 47 + let ptr = unsafe { self.buf.add(offset) }; 54 48 55 49 // SAFETY: 56 50 // - `ptr` is a valid pointer to a `Vmalloc` allocation.