All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: Tamir Duberstein <tamird@kernel.org>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Christian Brauner" <brauner@kernel.org>,
	"Carlos Llamas" <cmllamas@google.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH 4/6] rust: binder: enable `clippy::ref_as_ptr` lint
Date: Tue, 26 May 2026 12:46:11 +0000	[thread overview]
Message-ID: <ahWWE_zdHnzjhUpY@google.com> (raw)
In-Reply-To: <20260522-binder-strict-provenance-v1-4-3d6e9406e864@kernel.org>

On Fri, May 22, 2026 at 07:12:49PM +0200, Tamir Duberstein wrote:
> In Rust 1.78.0, Clippy introduced the `ref_as_ptr` lint [1]:
> 
> > Using `as` casts may result in silently changing mutability or type.
> 
> While this does not eliminate unchecked `as` conversions, it makes such
> conversions easier to scrutinize. It also has the slight benefit of
> removing a degree of freedom on which to bikeshed. Thus apply the 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#ref_as_ptr [1]
> Signed-off-by: Tamir Duberstein <tamird@kernel.org>
> ---
>  drivers/android/binder/node.rs             | 2 +-
>  drivers/android/binder/page_range.rs       | 4 ++--
>  drivers/android/binder/rust_binder_main.rs | 2 +-
>  drivers/android/binder/trace.rs            | 2 +-
>  4 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/android/binder/node.rs b/drivers/android/binder/node.rs
> index d710940c3c8f..a4a3ddda6ac9 100644
> --- a/drivers/android/binder/node.rs
> +++ b/drivers/android/binder/node.rs
> @@ -321,7 +321,7 @@ pub(crate) unsafe fn remove_node_info(
>      /// An id that is unique across all binder nodes on the system. Used as the key in the
>      /// `by_node` map.
>      pub(crate) fn global_id(&self) -> usize {
> -        (self as *const Node).addr()
> +        core::ptr::from_ref(self).addr()

Can we please import core::ptr?

>      }
>  
>      pub(crate) fn get_id(&self) -> (u64, u64) {
> diff --git a/drivers/android/binder/page_range.rs b/drivers/android/binder/page_range.rs
> index 927b0802e80d..93e79c08b89a 100644
> --- a/drivers/android/binder/page_range.rs
> +++ b/drivers/android/binder/page_range.rs
> @@ -312,7 +312,7 @@ pub(crate) fn register_with_vma(&self, vma: &virt::VmaNew) -> Result<usize> {
>  
>          // SAFETY: This just initializes the pages array.
>          unsafe {
> -            let self_ptr = self as *const ShrinkablePageRange;
> +            let self_ptr = core::ptr::from_ref(self);
>              for i in 0..num_pages {
>                  let info = pages.as_mut_ptr().add(i);
>                  (&raw mut (*info).range).write(self_ptr);
> @@ -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).cast::<u8>().add(obj_offset);
> +                let obj_ptr = core::ptr::from_ref(obj).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;
> diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/binder/rust_binder_main.rs
> index fa28697982d3..88da29413e16 100644
> --- a/drivers/android/binder/rust_binder_main.rs
> +++ b/drivers/android/binder/rust_binder_main.rs
> @@ -6,7 +6,7 @@
>  
>  #![crate_name = "rust_binder"]
>  #![recursion_limit = "256"]
> -#![allow(clippy::as_underscore, clippy::ref_as_ptr, clippy::cast_lossless)]
> +#![allow(clippy::as_underscore, clippy::cast_lossless)]
>  
>  use kernel::{
>      bindings::{self, seq_file},
> diff --git a/drivers/android/binder/trace.rs b/drivers/android/binder/trace.rs
> index 5539672d7285..b6cae57801fc 100644
> --- a/drivers/android/binder/trace.rs
> +++ b/drivers/android/binder/trace.rs
> @@ -26,7 +26,7 @@
>  
>  #[inline]
>  fn raw_transaction(t: &Transaction) -> rust_binder_transaction {
> -    t as *const Transaction as rust_binder_transaction
> +    core::ptr::from_ref(t).cast_mut().cast()

This just removes the type annotations I had. I'm not sure it's
cleaner.

Alice

>  }
>  
>  #[inline]
> 
> -- 
> 2.54.0
> 

  reply	other threads:[~2026-05-26 12:46 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-22 17:12 [PATCH 0/6] rust: binder: reduce `as` casts Tamir Duberstein
2026-05-22 17:12 ` [PATCH 1/6] rust: binder: use strict provenance APIs Tamir Duberstein
2026-05-26 12:32   ` Alice Ryhl
2026-05-27 11:10   ` Gary Guo
2026-05-22 17:12 ` [PATCH 2/6] rust: binder: transmute transaction data Tamir Duberstein
2026-05-26 12:33   ` Alice Ryhl
2026-05-26 13:33     ` Tamir Duberstein
2026-05-26 13:36       ` Alice Ryhl
2026-05-26 13:39         ` Tamir Duberstein
2026-05-26 13:42           ` Alice Ryhl
2026-05-26 16:30             ` Tamir Duberstein
2026-05-26 17:47               ` Miguel Ojeda
2026-05-26 18:00                 ` Tamir Duberstein
2026-05-26 19:21                   ` Miguel Ojeda
2026-05-22 17:12 ` [PATCH 3/6] rust: binder: enable `clippy::ptr_as_ptr` lint Tamir Duberstein
2026-05-26 12:34   ` Alice Ryhl
2026-05-22 17:12 ` [PATCH 4/6] rust: binder: enable `clippy::ref_as_ptr` lint Tamir Duberstein
2026-05-26 12:46   ` Alice Ryhl [this message]
2026-05-26 13:37     ` Tamir Duberstein
2026-05-22 17:12 ` [PATCH 5/6] rust: binder: enable `clippy::as_underscore` Tamir Duberstein
2026-05-26 12:44   ` Alice Ryhl
2026-05-26 17:30     ` Tamir Duberstein
2026-05-22 17:12 ` [PATCH 6/6] rust: binder: enable `clippy::cast_lossless` Tamir Duberstein
2026-05-26 12:44   ` Alice Ryhl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ahWWE_zdHnzjhUpY@google.com \
    --to=aliceryhl@google.com \
    --cc=a.hindborg@kernel.org \
    --cc=arve@android.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=brauner@kernel.org \
    --cc=cmllamas@google.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tkjos@android.com \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.