Skip to content

Commit 161dd7b

Browse files
committed
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: rust-lang/rust#117691 [1] Link: rust-lang/rust#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 parent f309a6e commit 161dd7b

1 file changed

Lines changed: 1 addition & 7 deletions

File tree

rust/kernel/alloc/allocator/iter.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,9 @@ impl<'a> Iterator for VmallocPageIter<'a> {
4242
return None;
4343
}
4444

45-
// TODO: Use `NonNull::add()` instead, once the minimum supported compiler version is
46-
// bumped to 1.80 or later.
47-
//
4845
// SAFETY: `offset` is in the interval `[0, (self.page_count() - 1) * page::PAGE_SIZE]`,
4946
// 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) };
5448

5549
// SAFETY:
5650
// - `ptr` is a valid pointer to a `Vmalloc` allocation.

0 commit comments

Comments
 (0)