[PATCH 2/2] rust: use `as_{mut,ref}_unchecked()` in a couple of places

From: Victor Prokhorov

Date: Wed Apr 08 2026 - 05:31:06 EST


From: Victor Prokhorov <mail@xxxxxxxxxxxxxxxxxxx>

Replace `&*ptr` and `&mut *ptr` with `as_ref_unchecked()` and
`as_mut_unchecked()`, expressing the conversion as a named unsafe
operation rather than a syntactic pattern.

No functional change.

Suggested-by: Miguel Ojeda <ojeda@xxxxxxxxxx>
Link: https://github.com/Rust-for-Linux/linux/issues/1225
Signed-off-by: Victor Prokhorov <mail@xxxxxxxxxxxxxxxxxxx>
---
drivers/android/binder/page_range.rs | 2 +-
rust/kernel/net/phy.rs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/android/binder/page_range.rs b/drivers/android/binder/page_range.rs
index 8e9f5c4819d0..ecd77c6a9e30 100644
--- a/drivers/android/binder/page_range.rs
+++ b/drivers/android/binder/page_range.rs
@@ -672,7 +672,7 @@ fn drop(self: Pin<&mut Self>) {
// CAST: The `list_head` field is first in `PageInfo`.
let info = item as *mut PageInfo;
// SAFETY: The `range` field of `PageInfo` is immutable.
- let range = unsafe { &*((*info).range) };
+ let range = unsafe { (*info).range.as_ref_unchecked() };

mm = match range.mm.mmget_not_zero() {
Some(mm) => MmWithUser::into_mmput_async(mm),
diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
index 3ca99db5cccf..221c50ccbfa0 100644
--- a/rust/kernel/net/phy.rs
+++ b/rust/kernel/net/phy.rs
@@ -88,7 +88,7 @@ unsafe fn from_raw<'a>(ptr: *mut bindings::phy_device) -> &'a mut Self {
let ptr = ptr.cast::<Self>();
// SAFETY: by the function requirements the pointer is valid and we have unique access for
// the duration of `'a`.
- unsafe { &mut *ptr }
+ unsafe { ptr.as_mut_unchecked() }
}

/// Gets the id of the PHY.
--
2.51.0