Re: [PATCH 3/6] rust: binder: enable `clippy::ptr_as_ptr` lint

From: Alice Ryhl

Date: Tue May 26 2026 - 08:35:58 EST


On Fri, May 22, 2026 at 07:12:48PM +0200, Tamir Duberstein wrote:
> In Rust 1.51.0, Clippy introduced the `ptr_as_ptr` lint [1]:
>
> > Though `as` casts between raw pointers are not terrible,
> > `pointer::cast` is safer because it cannot accidentally change pointer
> > mutability or cast the pointer to other types like `usize`.
>
> Apply the required changes and enable the lint in the Binder Rust driver
> -- no functional change intended.
>
> Link: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr [1]
> Signed-off-by: Tamir Duberstein <tamird@xxxxxxxxxx>

Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>

> drivers/android/binder/page_range.rs | 6 +++---
> drivers/android/binder/rust_binder_main.rs | 7 +------
> 2 files changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/android/binder/page_range.rs b/drivers/android/binder/page_range.rs
> index e54a90e62402..927b0802e80d 100644
> --- a/drivers/android/binder/page_range.rs
> +++ b/drivers/android/binder/page_range.rs
> @@ -571,7 +571,7 @@ pub(crate) unsafe fn read<T: FromBytes>(&self, offset: usize) -> Result<T> {
> unsafe {
> self.iterate(offset, size_of::<T>(), |page, offset, to_copy| {
> // SAFETY: The sum of `offset` and `to_copy` is bounded by the size of T.
> - let obj_ptr = (out.as_mut_ptr() as *mut u8).add(out_offset);
> + let obj_ptr = out.as_mut_ptr().cast::<u8>().add(out_offset);
> // SAFETY: The pointer points is in-bounds of the `out` variable, so it is valid.
> page.read_raw(obj_ptr, offset, to_copy)?;
> out_offset += to_copy;
> @@ -593,7 +593,7 @@ pub(crate) unsafe fn write<T: ?Sized>(&self, offset: usize, obj: &T) -> Result {
> unsafe {
> self.iterate(offset, size_of_val(obj), |page, offset, to_copy| {
> // SAFETY: The sum of `offset` and `to_copy` is bounded by the size of T.
> - let obj_ptr = (obj as *const T as *const u8).add(obj_offset);
> + let obj_ptr = (obj as *const T).cast::<u8>().add(obj_offset);
> // SAFETY: We have a reference to the object, so the pointer is valid.
> page.write_raw(obj_ptr, offset, to_copy)?;
> obj_offset += to_copy;
> @@ -712,7 +712,7 @@ fn drop(self: Pin<&mut Self>) {
>
> {
> // CAST: The `list_head` field is first in `PageInfo`.
> - let info = item as *mut PageInfo;
> + let info = item.cast::<PageInfo>();
> // SAFETY: The `range` field of `PageInfo` is immutable.
> range_ptr = unsafe { (*info).range };
> // SAFETY: The `range` outlives its `PageInfo` values.
> diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/binder/rust_binder_main.rs
> index d487638266e3..fa28697982d3 100644
> --- a/drivers/android/binder/rust_binder_main.rs
> +++ b/drivers/android/binder/rust_binder_main.rs
> @@ -6,12 +6,7 @@
>
> #![crate_name = "rust_binder"]
> #![recursion_limit = "256"]
> -#![allow(
> - clippy::as_underscore,
> - clippy::ref_as_ptr,
> - clippy::ptr_as_ptr,
> - clippy::cast_lossless
> -)]
> +#![allow(clippy::as_underscore, clippy::ref_as_ptr, clippy::cast_lossless)]
>
> use kernel::{
> bindings::{self, seq_file},
>
> --
> 2.54.0
>