From nobody Mon Jun 8 20:41:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E227421F17; Tue, 26 May 2026 18:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779820757; cv=none; b=qw8uXoKNJqFhU2fwZJJXyje38QxpDnMMRAT797wGMW4bR/7PP5aETgW+Z8evUGGasy4ZAB3HXKSX1Pht0xfkDf5bJ0bdJlNLBFT0Cxjit1hAYBDOoH03DDwHsK+9azKpqNQIOqIpllvFcptvW/7nEWDhhs5OHbk31yxi9iI+xlY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779820757; c=relaxed/simple; bh=HIPAI+gUYy/tezJYVYGax62hlmgvOHncbMGVwJG2+vw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NfnbOcWce1zbSNDSZiMAPtybzWfurThF9Zx+HJQvcw53fT76RPtMAO6YZzwyjiJqPGtzk+q6p69EqwsoeamLbv7oyFHPlcN+EzNgrpQpTcBmyRwVRhxvPlxAlvlUHk/ZO0JmtcMOzV0hqrDeLw/rvxBune8Vbth1FtJWz9TSxTU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OiAdqfeo; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OiAdqfeo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A05191F00A3D; Tue, 26 May 2026 18:39:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779820756; bh=i6JQKpUTWXOUpG1pnzJDmEEx4U1fiyb87oZZbyIFwa8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=OiAdqfeoGQoLs2L+12cvseOho9mYaCvUGkix4gLFyMnB/nF4wZxAyMbNPxjBEy7+b HNu3W9OdhTOhqF24N1DHORpPdcDWnrqIziFHx2vU9Dwq4lf9zQM26Jdihurz9RawBW Pw/GwZnxyYM/yPZ4vP15Ga6hKsX0R6PhFyXDdat4VncM/D+Bh7usYEvmrBLJAKdcrZ U8IygNdrnRfKxTUHvHHLL/RhXAA7iPJNaMywcxKLjDpW4Wk3J3dHQ5Kesh07Fusrzz dAXFeDiolsjZAuBLdSmeTth7wXQIAsG7jXTrh/3YZIrwx0xkkk7gQ8Sp9hs0RuShMH sfxJFyRhshLZQ== From: Tamir Duberstein Date: Tue, 26 May 2026 14:39:07 -0400 Subject: [PATCH v2 1/5] rust: binder: use strict provenance APIs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260526-binder-strict-provenance-v2-1-a41d89c29bc5@kernel.org> References: <20260526-binder-strict-provenance-v2-0-a41d89c29bc5@kernel.org> In-Reply-To: <20260526-binder-strict-provenance-v2-0-a41d89c29bc5@kernel.org> To: Greg Kroah-Hartman , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas , Alice Ryhl , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich Cc: Tamir Duberstein , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2047; i=tamird@kernel.org; h=from:subject:message-id; bh=HIPAI+gUYy/tezJYVYGax62hlmgvOHncbMGVwJG2+vw=; b=owGbwMvMwCV2wYdPVfy60HTG02pJDFmiL87fy7ulcr9IWmN19Y2tx8Rir1qIqB1JE9qlYVW/q Fuo4lJlx0QWBjEuBksxRZZE0UN701Nv75HNfHccZg4rE8gQaZEGBiBgYeDLTcwrNdIx0jPVNtQz NNIx0DFm4OIUgKmev4nhf+7OSoXzW6QYdv5/HWzzRkUn8tzjIK8ETeX0dk17NqlnCxkZHu7c/dZ ok8nBZOG7jO4cJ36EnrV3MTrS/KV9W9m8e+I+XAA= X-Developer-Key: i=tamird@kernel.org; a=openpgp; fpr=5A6714204D41EC844C50273C19D6FF6092365380 Replace the pointer-to-integer conversions in the Binder Rust driver with calls to the strict provenance APIs. The strict provenance APIs were stabilized in Rust 1.84.0 [1]. Since commit f32fb9c58a5b ("rust: bump Rust minimum supported version to 1.85.0 (Debian Trixie)"), the minimum supported Rust version is 1.85.0, so no polyfills are needed. Link: https://blog.rust-lang.org/2025/01/09/Rust-1.84.0.html#strict-provena= nce-apis [1] Reviewed-by: Alice Ryhl Assisted-by: Codex:gpt-5 Signed-off-by: Tamir Duberstein --- drivers/android/binder/node.rs | 2 +- drivers/android/binder/rust_binder_main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/android/binder/node.rs b/drivers/android/binder/node.rs index 69f757ff7461..d710940c3c8f 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 a= s the key in the /// `by_node` map. pub(crate) fn global_id(&self) -> usize { - self as *const Node as usize + (self as *const Node).addr() } =20 pub(crate) fn get_id(&self) -> (u64, u64) { diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/b= inder/rust_binder_main.rs index dc1941cd2407..d487638266e3 100644 --- a/drivers/android/binder/rust_binder_main.rs +++ b/drivers/android/binder/rust_binder_main.rs @@ -511,7 +511,7 @@ unsafe impl Sync for AssertSync {} _: *mut kernel::ffi::c_void, ) -> kernel::ffi::c_int { // SAFETY: Accessing the private field of `seq_file` is okay. - let pid =3D (unsafe { (*ptr).private }) as usize as Pid; + let pid =3D unsafe { (*ptr).private }.addr() as Pid; // SAFETY: The caller ensures that the pointer is valid and exclusive = for the duration in which // this method is called. let m =3D unsafe { SeqFile::from_raw(ptr) }; --=20 2.54.0 From nobody Mon Jun 8 20:41:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18F37421A17; Tue, 26 May 2026 18:39:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779820760; cv=none; b=OeGNJGTaGUX/5lIGtlU4LjNh0ZTjxSTLTxZzNVS0Fol+Sffhd5qI4pD2f6ZsQf8dCgZ4hyxh93zi18RB5dnfqTk22IXlHh5pPwszSzI8+Ucf3G96Pp7F8PLgq8nPCS6nE56DQ7Mv/7nAgrDsQ6Xq6jVHjBpiWWaPcSoE/UXlvHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779820760; c=relaxed/simple; bh=uYuX75K78hn7XCGsIeT0S73HSWjlvPu++DoAz4YF2e8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=e8YWX+BE4mgyyrPqs1BwjULU1JBwbFasAekw+lEz7tksSs1U0w9PoWEKfgeAJ7OzKH7wQDhkxpN/lng/6OHK2YHjusccmV6LKZyypEiL3I9ZUx+XCJCOrFYTuvTInqowoyhptEaSGCi9zdrvCU55+TjvIxXKqSY/AF79Ie0i80Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TkGjXS+C; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TkGjXS+C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 606981F00A3F; Tue, 26 May 2026 18:39:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779820757; bh=HfphQOKmTvqT1yBrMnbtpb3V6YzN4TXyixD8aCJLnSU=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=TkGjXS+CSSjmhT25/FvkHJhopHWrUmxUC/BtpB5pp4+pKMsKsKQ2p1GJUqNankBAP 9gcMXoq52l1sew4eRLyY4jv9Q4CIyeCgSCKWp0RiJq2fxjKqRcBWp3vfFNUPlxwQZ3 LOtqunIcc2m3mH6h9GbUVdr9afek7QY00+nhPIqaa7pUmkcneYYCT96EVOzzy+L06X Zi9X0xLO8U/d+njSg+GraP4gHTvxhpLJ5q2k2Z5lhbred4lz7E8VzMvUsIaAIfyaZ8 W8MGwM3U02GAnE/paeXoxNM1gjbCSr9mIRVUK962mvL782UmLhSm79n98hyIfPfPaj OrR1Y8nrD0DjA== From: Tamir Duberstein Date: Tue, 26 May 2026 14:39:08 -0400 Subject: [PATCH v2 2/5] rust: binder: enable `clippy::ptr_as_ptr` lint Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260526-binder-strict-provenance-v2-2-a41d89c29bc5@kernel.org> References: <20260526-binder-strict-provenance-v2-0-a41d89c29bc5@kernel.org> In-Reply-To: <20260526-binder-strict-provenance-v2-0-a41d89c29bc5@kernel.org> To: Greg Kroah-Hartman , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas , Alice Ryhl , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich Cc: Tamir Duberstein , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3967; i=tamird@kernel.org; h=from:subject:message-id; bh=uYuX75K78hn7XCGsIeT0S73HSWjlvPu++DoAz4YF2e8=; b=owGbwMvMwCV2wYdPVfy60HTG02pJDFmiLy4ouWZt+CO4i7kyo8PrkxizzvY1mVKpsbdX2oi/P vSo+XdHx0QWBjEuBksxRZZE0UN701Nv75HNfHccZg4rE8gQaZEGBiBgYeDLTcwrNdIx0jPVNtQz NNIx0DFm4OIUgKlWaGdkeKXFoF+Qcuw9+4yz7BrJxmJeN5r2cJcl3qxLUo3KmmYow8hwwD2q84r kia0xOrZ2fZG+2/XuFDzOrZdcOs10TuBq9j+sAA== X-Developer-Key: i=tamird@kernel.org; a=openpgp; fpr=5A6714204D41EC844C50273C19D6FF6092365380 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] Assisted-by: Codex:gpt-5 Signed-off-by: Tamir Duberstein Reviewed-by: Alice Ryhl --- drivers/android/binder/defs.rs | 4 ++-- drivers/android/binder/page_range.rs | 6 +++--- drivers/android/binder/rust_binder_main.rs | 7 +------ 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/android/binder/defs.rs b/drivers/android/binder/defs.rs index 33f51b4139c7..354c32c39e83 100644 --- a/drivers/android/binder/defs.rs +++ b/drivers/android/binder/defs.rs @@ -165,8 +165,8 @@ impl BinderTransactionDataSecctx { pub(crate) fn tr_data(&mut self) -> &mut BinderTransactionData { // SAFETY: Transparent wrapper is safe to transmute. unsafe { - &mut *(&mut self.transaction_data as *mut uapi::binder_transac= tion_data - as *mut BinderTransactionData) + &mut *((&mut self.transaction_data as *mut uapi::binder_transa= ction_data) + .cast::()) } } } 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(&self, offset: = usize) -> Result { unsafe { self.iterate(offset, size_of::(), |page, offset, to_copy| { // SAFETY: The sum of `offset` and `to_copy` is bounded by= the size of T. - let obj_ptr =3D (out.as_mut_ptr() as *mut u8).add(out_offs= et); + let obj_ptr =3D out.as_mut_ptr().cast::().add(out_offs= et); // SAFETY: The pointer points is in-bounds of the `out` va= riable, so it is valid. page.read_raw(obj_ptr, offset, to_copy)?; out_offset +=3D to_copy; @@ -593,7 +593,7 @@ pub(crate) unsafe fn write(&self, offset: us= ize, 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 =3D (obj as *const T as *const u8).add(obj_off= set); + let obj_ptr =3D (obj as *const T).cast::().add(obj_off= set); // SAFETY: We have a reference to the object, so the point= er is valid. page.write_raw(obj_ptr, offset, to_copy)?; obj_offset +=3D to_copy; @@ -712,7 +712,7 @@ fn drop(self: Pin<&mut Self>) { =20 { // CAST: The `list_head` field is first in `PageInfo`. - let info =3D item as *mut PageInfo; + let info =3D item.cast::(); // SAFETY: The `range` field of `PageInfo` is immutable. range_ptr =3D unsafe { (*info).range }; // SAFETY: The `range` outlives its `PageInfo` values. diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/b= inder/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 @@ =20 #![crate_name =3D "rust_binder"] #![recursion_limit =3D "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)] =20 use kernel::{ bindings::{self, seq_file}, --=20 2.54.0 From nobody Mon Jun 8 20:41:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 034D441B340; Tue, 26 May 2026 18:39:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779820764; cv=none; b=jjgBU61yv76Ah8vjSySOSU3aAgN4bNYerg6e+SXc/H3qUwp5WRtg7IlgajOcPK4vyd6LpxrytCPUoI2y1g46UXr/047DNzBk+9yKsMnNhZPqOuzPrtc2rZcDe2oomUMMk0Uq3SDrbV09iUgihL7CLbDGu0i1Y1QCuU5pp4Cndoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779820764; c=relaxed/simple; bh=eKpcFFCz8AEyFkOL4tjabqd6EKmHdZ/39RohcFkt3nQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qq4A98uBXtll8nIWtTz8CgWm283gvkuMp31ximIF3Nhe9UEywHFp4hzOg185y3kpTDyPFavxcu9xUa3+5yc900dkK1T+qSc23ZfW0iWblstOdfH9w4o2HEJArTEDbKyvjj6FU9hQhOkOV1x1u/AsDFeLG4jAx4l17WR+kAvWtBU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cia3p14+; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cia3p14+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 238DC1F000E9; Tue, 26 May 2026 18:39:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779820759; bh=4mjeMms1+mF103piHZP9toutrr6UOWv96bYcO8DEGMs=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=cia3p14+yXEpeaGlsLNDDY/gUl08iYqHF47Laen8V+FAA1EmQSlg6b4UWWLDkmhsJ a1mz1oEwe0t9aXwbyTHREOG/fv4IhhZae6fcxeiX60/u3TEjhY11H+t5IfVunp2bTe 19fbEVyU0Qzc/56/41rlQkdm6kbs0RaSSmtVg4MtymzpZxBUkhQyCE9CG0vqbbA7iE 3+QueazOBSSMdFwJdOPq6PLRio99eXXYkJucjaVaJIAjexTk3IIbn7wBoGf9UkS88A Lu1QlGFBHpQDR4jU0vXbRQz+fdmlTtCku+2TEcfW7+bOgCsNtKfV5Bx9IJFC+ESX2K h7Yl2Of/SJRkA== From: Tamir Duberstein Date: Tue, 26 May 2026 14:39:09 -0400 Subject: [PATCH v2 3/5] rust: binder: enable `clippy::ref_as_ptr` lint Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260526-binder-strict-provenance-v2-3-a41d89c29bc5@kernel.org> References: <20260526-binder-strict-provenance-v2-0-a41d89c29bc5@kernel.org> In-Reply-To: <20260526-binder-strict-provenance-v2-0-a41d89c29bc5@kernel.org> To: Greg Kroah-Hartman , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas , Alice Ryhl , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich Cc: Tamir Duberstein , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4934; i=tamird@kernel.org; h=from:subject:message-id; bh=eKpcFFCz8AEyFkOL4tjabqd6EKmHdZ/39RohcFkt3nQ=; b=owGbwMvMwCV2wYdPVfy60HTG02pJDFmiLy78jHLp+TOf+4nVxNyFp1Z/aOV1XBdxeMJ2OWmLH 69Efkh865jIwiDGxWAppsiSKHpob3rq7T2yme+Ow8xhZQIZIi3SwAAELAx8uYl5pUY6Rnqm2oZ6 hkY6BjrGDFycAjDVN9oYGV5e8RJaP6+05Lxpru6Rz5t83dg2y4YcqXxpa7Vx0b43q5sZ/gpvWG6 wu/RzwjzNhszpbJNnl8T+nOTWWn/r3u2+nwce32YEAA== X-Developer-Key: i=tamird@kernel.org; a=openpgp; fpr=5A6714204D41EC844C50273C19D6FF6092365380 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] Assisted-by: Codex:gpt-5 Signed-off-by: Tamir Duberstein Reviewed-by: Alice Ryhl --- drivers/android/binder/defs.rs | 4 +++- drivers/android/binder/node.rs | 3 ++- drivers/android/binder/page_range.rs | 4 ++-- drivers/android/binder/rust_binder_main.rs | 2 +- drivers/android/binder/trace.rs | 4 +++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/android/binder/defs.rs b/drivers/android/binder/defs.rs index 354c32c39e83..e697c2c13e29 100644 --- a/drivers/android/binder/defs.rs +++ b/drivers/android/binder/defs.rs @@ -4,6 +4,8 @@ =20 use core::mem::MaybeUninit; use core::ops::{Deref, DerefMut}; +use core::ptr; + use kernel::{ transmute::{AsBytes, FromBytes}, uapi::{self, *}, @@ -165,7 +167,7 @@ impl BinderTransactionDataSecctx { pub(crate) fn tr_data(&mut self) -> &mut BinderTransactionData { // SAFETY: Transparent wrapper is safe to transmute. unsafe { - &mut *((&mut self.transaction_data as *mut uapi::binder_transa= ction_data) + &mut *(ptr::from_mut::(&mut sel= f.transaction_data) .cast::()) } } diff --git a/drivers/android/binder/node.rs b/drivers/android/binder/node.rs index d710940c3c8f..3d96738dee66 100644 --- a/drivers/android/binder/node.rs +++ b/drivers/android/binder/node.rs @@ -21,6 +21,7 @@ }; =20 use core::mem; +use core::ptr; =20 mod wrapper; pub(crate) use self::wrapper::CritIncrWrapper; @@ -321,7 +322,7 @@ pub(crate) unsafe fn remove_node_info( /// An id that is unique across all binder nodes on the system. Used a= s the key in the /// `by_node` map. pub(crate) fn global_id(&self) -> usize { - (self as *const Node).addr() + ptr::from_ref(self).addr() } =20 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..719fa0175e0b 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::VmaN= ew) -> Result { =20 // SAFETY: This just initializes the pages array. unsafe { - let self_ptr =3D self as *const ShrinkablePageRange; + let self_ptr =3D ptr::from_ref(self); for i in 0..num_pages { let info =3D pages.as_mut_ptr().add(i); (&raw mut (*info).range).write(self_ptr); @@ -593,7 +593,7 @@ pub(crate) unsafe fn write(&self, offset: us= ize, 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 =3D (obj as *const T).cast::().add(obj_off= set); + let obj_ptr =3D ptr::from_ref(obj).cast::().add(obj_of= fset); // SAFETY: We have a reference to the object, so the point= er is valid. page.write_raw(obj_ptr, offset, to_copy)?; obj_offset +=3D to_copy; diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/b= inder/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 @@ =20 #![crate_name =3D "rust_binder"] #![recursion_limit =3D "256"] -#![allow(clippy::as_underscore, clippy::ref_as_ptr, clippy::cast_lossless)] +#![allow(clippy::as_underscore, clippy::cast_lossless)] =20 use kernel::{ bindings::{self, seq_file}, diff --git a/drivers/android/binder/trace.rs b/drivers/android/binder/trace= .rs index 5539672d7285..06aabb3cc2f1 100644 --- a/drivers/android/binder/trace.rs +++ b/drivers/android/binder/trace.rs @@ -4,6 +4,8 @@ =20 use crate::transaction::Transaction; =20 +use core::ptr; + use kernel::bindings::{rust_binder_transaction, task_struct}; use kernel::error::Result; use kernel::ffi::{c_int, c_uint, c_ulong}; @@ -26,7 +28,7 @@ =20 #[inline] fn raw_transaction(t: &Transaction) -> rust_binder_transaction { - t as *const Transaction as rust_binder_transaction + ptr::from_ref(t).cast_mut().cast() } =20 #[inline] --=20 2.54.0 From nobody Mon Jun 8 20:41:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C577C426699; Tue, 26 May 2026 18:39:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779820766; cv=none; b=cD80UYX7CeM6Y3fnzmAf90/2kzX63QbjNlzdrUn0XbafaD22TBD0vlQzX9lqbOuVCTvu6kaDo8N6FIoRauGDDEZwOtrkO3OG98pU3WKwDLF3qBbLFVrQXSgW0FuEqJWD45FaZP8JrMdJOTMhyiY+3vI8MSh6KbcKgr/AE2xMiPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779820766; c=relaxed/simple; bh=hDDPWOs/safUlJLPOV9TbsGKzlNTkzgW9WcBwV8On6Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XhwQ0XdyZ/Ai3kx3iZl+xN/N9panjJG3ec4x/M3qJfZA33B2WXs4HjpQWptHLh48Bwk5D4hht4wIJ8yws14ew7ZXFlwNRl6BQV+MKRub/nK315B93tEDUCOm/cfhRM9Ie+TH+6GVWN1kNrQCB1zpt5RuyNvQO8wAsx2Lb4lIXuw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Y6zYGWXm; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Y6zYGWXm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6F0E1F01558; Tue, 26 May 2026 18:39:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779820761; bh=xN3ds+X8QR47mPHuy8CP8Eh10MqiacB5ujNAN8JQUPo=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Y6zYGWXmkMzMgRnHjipQshI5fJGYs/TuE+2Nu4RU/TJ2JW/iKtR4SUNUfVoxNAUwL 1/nADxYKTb+Jv16+DbWzyl/2rDFdQtVvm/wOYxf8Vizd8rzExDiclDV3y8vE8dWrn7 V22MArrcoqbUgjhgYs+odJhE9QBGIwJJQAhDn/2tY+ra6maPg1ZlnStN0IASw7S6Hz FpCSsBetihxK5REgQRx4G9MyCdmPfKUE18Z5wXODwZNIZZiNerZtZQjPYoSOkhUnKo ImDkX621nDWxogkYzzYegTUrHojnPNFqLHBec6TSQoDCuKr2LTTjsLm9eydFdy+qCC K+e20uE69kKIA== From: Tamir Duberstein Date: Tue, 26 May 2026 14:39:10 -0400 Subject: [PATCH v2 4/5] rust: binder: enable `clippy::as_underscore` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260526-binder-strict-provenance-v2-4-a41d89c29bc5@kernel.org> References: <20260526-binder-strict-provenance-v2-0-a41d89c29bc5@kernel.org> In-Reply-To: <20260526-binder-strict-provenance-v2-0-a41d89c29bc5@kernel.org> To: Greg Kroah-Hartman , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas , Alice Ryhl , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich Cc: Tamir Duberstein , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=14342; i=tamird@kernel.org; h=from:subject:message-id; bh=hDDPWOs/safUlJLPOV9TbsGKzlNTkzgW9WcBwV8On6Q=; b=owGbwMvMwCV2wYdPVfy60HTG02pJDFmiLy7c51TfJaNjcVyhtJvhj8mVF/tdA87Pv6C3LSjX8 4qj0/32joksDGJcDJZiiiyJoof2pqfe3iOb+e44zBxWJpAh0iINDEDAwsCXm5hXaqRjpGeqbahn aKRjoGPMwMUpAFOtasfIsELn6903gnuVfv/j2v3oeogy55agJs8zxfyCTw193CcuXs3IsH6yRfu v8kcL173feSxm8895iwSjFX4zzd2/hH9li+2rUm4A X-Developer-Key: i=tamird@kernel.org; a=openpgp; fpr=5A6714204D41EC844C50273C19D6FF6092365380 In Rust 1.63.0, Clippy introduced the `as_underscore` lint [1]: > The conversion might include lossy conversion or a dangerous cast that > might go undetected due to the type being inferred. > > The lint is allowed by default as using `_` is less wordy than always > specifying the type. Always specifying the type is especially helpful in function call contexts where the inferred type may change at a distance. Specifying the type also allows Clippy to spot more cases of `useless_conversion`. Several inferred conversions from `binder_uintptr_t` to the driver's internal `u64` node identifiers are identity conversions. Although the UAPI header retains `BINDER_IPC_32BIT` for userspace building against older kernels, commit 1190b4e38f97 ("ANDROID: binder: remove 32-bit binder interface.") removed kernel support for selecting that protocol. Rust Binder therefore uses the 64-bit Binder protocol on every supported architecture. 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#as_undersco= re [1] Assisted-by: Codex:gpt-5 Signed-off-by: Tamir Duberstein Reviewed-by: Alice Ryhl --- drivers/android/binder/allocation.rs | 4 ++-- drivers/android/binder/defs.rs | 2 +- drivers/android/binder/node.rs | 11 ++++++----- drivers/android/binder/node/wrapper.rs | 2 +- drivers/android/binder/process.rs | 8 ++++---- drivers/android/binder/rust_binder_main.rs | 4 ++-- drivers/android/binder/thread.rs | 24 +++++++++++++----------- drivers/android/binder/transaction.rs | 14 ++++++++------ 8 files changed, 37 insertions(+), 32 deletions(-) diff --git a/drivers/android/binder/allocation.rs b/drivers/android/binder/= allocation.rs index 0cab959e4b7e..61fc08bcd6be 100644 --- a/drivers/android/binder/allocation.rs +++ b/drivers/android/binder/allocation.rs @@ -376,8 +376,8 @@ pub(crate) fn transfer_binder_object( BINDER_TYPE_WEAK_BINDER }; newobj.flags =3D obj.flags; - newobj.__bindgen_anon_1.binder =3D ptr as _; - newobj.cookie =3D cookie as _; + newobj.__bindgen_anon_1.binder =3D ptr as uapi::binder_uintptr= _t; + newobj.cookie =3D cookie as uapi::binder_uintptr_t; self.write(offset, &newobj)?; // Increment the user ref count on the node. It will be decrem= ented as part of the // destruction of the buffer, when we see a binder or weak-bin= der object. diff --git a/drivers/android/binder/defs.rs b/drivers/android/binder/defs.rs index e697c2c13e29..8ac9bdd7a499 100644 --- a/drivers/android/binder/defs.rs +++ b/drivers/android/binder/defs.rs @@ -148,7 +148,7 @@ fn default() -> Self { impl BinderVersion { pub(crate) fn current() -> Self { Self(MaybeUninit::new(uapi::binder_version { - protocol_version: BINDER_CURRENT_PROTOCOL_VERSION as _, + protocol_version: BINDER_CURRENT_PROTOCOL_VERSION as i32, })) } } diff --git a/drivers/android/binder/node.rs b/drivers/android/binder/node.rs index 3d96738dee66..4e75f58bf0db 100644 --- a/drivers/android/binder/node.rs +++ b/drivers/android/binder/node.rs @@ -9,6 +9,7 @@ seq_print, sync::lock::{spinlock::SpinLockBackend, Guard}, sync::{Arc, LockedBy, SpinLock}, + uapi, }; =20 use crate::{ @@ -465,7 +466,7 @@ pub(crate) fn incr_refcount_allow_zero2one_with_wrapper( owner_inner: &mut ProcessInner, ) -> Option> { match self.incr_refcount_allow_zero2one(strong, owner_inner) { - Ok(Some(node)) =3D> Some(node as _), + Ok(Some(node)) =3D> Some(node as DLArc), Ok(None) =3D> None, Err(CouldNotDeliverCriticalIncrement) =3D> { assert!(strong); @@ -490,8 +491,8 @@ pub(crate) fn populate_counts( guard: &Guard<'_, ProcessInner, SpinLockBackend>, ) { let inner =3D self.inner.access(guard); - out.strong_count =3D inner.strong.count as _; - out.weak_count =3D inner.weak.count as _; + out.strong_count =3D inner.strong.count as u32; + out.weak_count =3D inner.weak.count as u32; } =20 pub(crate) fn populate_debug_info( @@ -499,8 +500,8 @@ pub(crate) fn populate_debug_info( out: &mut BinderNodeDebugInfo, guard: &Guard<'_, ProcessInner, SpinLockBackend>, ) { - out.ptr =3D self.ptr as _; - out.cookie =3D self.cookie as _; + out.ptr =3D self.ptr as uapi::binder_uintptr_t; + out.cookie =3D self.cookie as uapi::binder_uintptr_t; let inner =3D self.inner.access(guard); if inner.strong.has_count { out.has_strong_ref =3D 1; diff --git a/drivers/android/binder/node/wrapper.rs b/drivers/android/binde= r/node/wrapper.rs index 43294c050502..6e4ca01c941a 100644 --- a/drivers/android/binder/node/wrapper.rs +++ b/drivers/android/binder/node/wrapper.rs @@ -21,7 +21,7 @@ pub(crate) fn new() -> Result { =20 pub(super) fn init(self, node: DArc) -> DLArc= { match self.inner.pin_init_with(DTRWrap::new(NodeWrapper { node }))= { - Ok(initialized) =3D> ListArc::from(initialized) as _, + Ok(initialized) =3D> ListArc::from(initialized) as DLArc, Err(err) =3D> match err {}, } } diff --git a/drivers/android/binder/process.rs b/drivers/android/binder/pro= cess.rs index 820cbd541435..935f04eb2981 100644 --- a/drivers/android/binder/process.rs +++ b/drivers/android/binder/process.rs @@ -32,7 +32,7 @@ lock::{spinlock::SpinLockBackend, Guard}, Arc, ArcBorrow, CondVar, CondVarTimeoutResult, Mutex, SpinLock, Un= iqueArc, }, - task::Task, + task::{Pid, Task}, uaccess::{UserSlice, UserSliceReader}, uapi, workqueue::{self, Work}, @@ -259,7 +259,7 @@ pub(crate) fn new_node_ref_with_thread( let push =3D match wrapper { None =3D> node .incr_refcount_allow_zero2one(strong, self)? - .map(|node| node as _), + .map(|node| node as DLArc), Some(wrapper) =3D> node.incr_refcount_allow_zero2one_with_wrap= per(strong, wrapper, self), }; if let Some(node) =3D push { @@ -741,7 +741,7 @@ fn set_as_manager( } else { (0, 0, 0) }; - let node_ref =3D self.get_node(ptr, cookie, flags as _, true, thre= ad)?; + let node_ref =3D self.get_node(ptr, cookie, flags, true, thread)?; let node =3D node_ref.node.clone(); self.ctx.set_manager_node(node_ref)?; self.inner.lock().is_manager =3D true; @@ -1517,7 +1517,7 @@ fn get_frozen_status(data: UserSlice) -> Result { =20 for ctx in crate::context::get_all_contexts()? { ctx.for_each_proc(|proc| { - if proc.task.pid() =3D=3D info.pid as _ { + if proc.task.pid() =3D=3D info.pid as Pid { found =3D true; let inner =3D proc.inner.lock(); let txns_pending =3D inner.txns_pending_locked(); diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/b= inder/rust_binder_main.rs index 88da29413e16..2c10a8cd3d88 100644 --- a/drivers/android/binder/rust_binder_main.rs +++ b/drivers/android/binder/rust_binder_main.rs @@ -6,7 +6,7 @@ =20 #![crate_name =3D "rust_binder"] #![recursion_limit =3D "256"] -#![allow(clippy::as_underscore, clippy::cast_lossless)] +#![allow(clippy::cast_lossless)] =20 use kernel::{ bindings::{self, seq_file}, @@ -412,7 +412,7 @@ unsafe impl Sync for AssertSync {} // SAFETY: We previously set `private_data` in `rust_binder_open`. let f =3D unsafe { Arc::::borrow((*file).private_data) }; // SAFETY: The caller ensures that the file is valid. - match Process::ioctl(f, unsafe { File::from_raw_file(file) }, cmd as _= , arg as _) { + match Process::ioctl(f, unsafe { File::from_raw_file(file) }, cmd, arg= ) { Ok(()) =3D> 0, Err(err) =3D> err.to_errno() as isize, } diff --git a/drivers/android/binder/thread.rs b/drivers/android/binder/thre= ad.rs index 97d5f31e8fe3..87298a8c597d 100644 --- a/drivers/android/binder/thread.rs +++ b/drivers/android/binder/thread.rs @@ -666,9 +666,9 @@ fn translate_object( let strong =3D obj.hdr.type_ =3D=3D BINDER_TYPE_BINDER; // SAFETY: `binder` is a `binder_uintptr_t`; any bit patte= rn is a valid // representation. - let ptr =3D unsafe { obj.__bindgen_anon_1.binder } as _; - let cookie =3D obj.cookie as _; - let flags =3D obj.flags as _; + let ptr =3D unsafe { obj.__bindgen_anon_1.binder }; + let cookie =3D obj.cookie; + let flags =3D obj.flags; let node =3D self .process .as_arc_borrow() @@ -679,7 +679,7 @@ fn translate_object( BinderObjectRef::Handle(obj) =3D> { let strong =3D obj.hdr.type_ =3D=3D BINDER_TYPE_HANDLE; // SAFETY: `handle` is a `u32`; any bit pattern is a valid= representation. - let handle =3D unsafe { obj.__bindgen_anon_1.handle } as _; + let handle =3D unsafe { obj.__bindgen_anon_1.handle }; let node =3D self.process.get_node_from_handle(handle, str= ong)?; security::binder_transfer_binder(&self.process.cred, &view= .alloc.process.cred)?; view.transfer_binder_object(offset, obj, strong, node)?; @@ -736,7 +736,7 @@ fn translate_object( ScatterGatherEntry { obj_index, offset: alloc_offset, - sender_uaddr: obj.buffer as _, + sender_uaddr: obj.buffer as usize, length: obj_length, pointer_fixups: KVec::new(), fixup_min_offset: 0, @@ -843,7 +843,7 @@ fn translate_object( .ok_or(EINVAL)?; =20 let mut fda_bytes =3D KVec::new(); - UserSlice::new(UserPtr::from_addr(fda_uaddr as _), fds_len) + UserSlice::new(UserPtr::from_addr(fda_uaddr as usize), fds= _len) .read_all(&mut fda_bytes, GFP_KERNEL)?; =20 if fds_len !=3D fda_bytes.len() { @@ -1365,7 +1365,7 @@ fn write(self: &Arc, req: &mut BinderWriteRead)= -> Result { let write_start =3D req.write_buffer.wrapping_add(req.write_consum= ed); let write_len =3D req.write_size.saturating_sub(req.write_consumed= ); let mut reader =3D - UserSlice::new(UserPtr::from_addr(write_start as _), write_len= as _).reader(); + UserSlice::new(UserPtr::from_addr(write_start as usize), write= _len as usize).reader(); =20 while reader.len() >=3D size_of::() && self.inner.lock().retu= rn_work.is_unused() { let before =3D reader.len(); @@ -1436,7 +1436,7 @@ fn read(self: &Arc, req: &mut BinderWriteRead, = wait: bool) -> Result { let read_start =3D req.read_buffer.wrapping_add(req.read_consumed); let read_len =3D req.read_size.saturating_sub(req.read_consumed); let mut writer =3D BinderReturnWriter::new( - UserSlice::new(UserPtr::from_addr(read_start as _), read_len a= s _).writer(), + UserSlice::new(UserPtr::from_addr(read_start as usize), read_l= en as usize).writer(), self, ); let (in_pool, has_transaction, thread_todo, use_proc_queue) =3D { @@ -1500,9 +1500,11 @@ fn read(self: &Arc, req: &mut BinderWriteRead,= wait: bool) -> Result { =20 // Write BR_SPAWN_LOOPER if the process needs more threads for its= pool. if has_noop_placeholder && in_pool && self.process.needs_thread() { - let mut writer =3D - UserSlice::new(UserPtr::from_addr(req.read_buffer as _), r= eq.read_size as _) - .writer(); + let mut writer =3D UserSlice::new( + UserPtr::from_addr(req.read_buffer as usize), + req.read_size as usize, + ) + .writer(); writer.write(&BR_SPAWN_LOOPER)?; } Ok(()) diff --git a/drivers/android/binder/transaction.rs b/drivers/android/binder= /transaction.rs index 47d5e4d88b07..e6cc4d403b99 100644 --- a/drivers/android/binder/transaction.rs +++ b/drivers/android/binder/transaction.rs @@ -11,6 +11,7 @@ task::{Kuid, Pid}, time::{Instant, Monotonic}, types::ScopeGuard, + uapi, }; =20 use crate::{ @@ -402,16 +403,17 @@ fn do_work( let tr =3D tr_sec.tr_data(); if let Some(target_node) =3D &self.target_node { let (ptr, cookie) =3D target_node.get_id(); - tr.target.ptr =3D ptr as _; - tr.cookie =3D cookie as _; + tr.target.ptr =3D ptr as uapi::binder_uintptr_t; + tr.cookie =3D cookie as uapi::binder_uintptr_t; }; tr.code =3D self.code; tr.flags =3D self.flags; - tr.data_size =3D self.data_size as _; - tr.data.ptr.buffer =3D self.data_address as _; - tr.offsets_size =3D self.offsets_size as _; + tr.data_size =3D self.data_size as uapi::binder_size_t; + tr.data.ptr.buffer =3D self.data_address as uapi::binder_uintptr_t; + tr.offsets_size =3D self.offsets_size as uapi::binder_size_t; if tr.offsets_size > 0 { - tr.data.ptr.offsets =3D (self.data_address + ptr_align(self.da= ta_size).unwrap()) as _; + tr.data.ptr.offsets =3D + (self.data_address + ptr_align(self.data_size).unwrap()) a= s uapi::binder_uintptr_t; } tr.sender_euid =3D self.sender_euid.into_uid_in_current_ns(); tr.sender_pid =3D 0; --=20 2.54.0 From nobody Mon Jun 8 20:41:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9B08421F1E; Tue, 26 May 2026 18:39:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779820766; cv=none; b=DtQoqFw99ey2fEoB7dSrX64rnGnkSp93z4qNiRoDzzxLPewAQhx+JVybJnYL5mdnblHPddJ6frC7JKkGoQfD/dHomO5rDfohNQZ0tY/iIch0qKVJLHtGlTZVWaS55CAxavO89kk0p0o+H5Eag1ddGlmbPe+X/kUPuieQkQVyiDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779820766; c=relaxed/simple; bh=kUy0AxwEksMj1GYxf8Qm6ShYGRejtRREh+yzuoHwPCI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YXR22tebG2K1uXFZE9Fn3QLzKv3Gc+yWNSM74L4DJfZ1G/209/6H5+iu9mR5ELyLI0Mw/WS4YvXFyhsU4gYuBtTa6KTqfigG4144BIPF3YxdKRE7jPrjn7lTfJWARKNXDSk3vBQGn3uqAAYMR2BhgvSPDrh9F1KgJZB0IKwMGYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EnWjmxTy; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EnWjmxTy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9587E1F00A3E; Tue, 26 May 2026 18:39:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779820763; bh=d164e65OFZzsXJRq3eFPhB3ObQzve80zcS4YF1dzDmo=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=EnWjmxTy6Rv6cxNISWwlTzoSsVPX/qNr3K26uEN0yGrnjpj7uMDUTDmJQlbSSGMHX wEBYpg9sTJoFGQbwuPdQSEq0Fr/X/aK1oAk7UcZ7MJFz/Gshy2n8pKPl1++7CqP1mp ra5vEdXEhP+wcZDqM25BWGEMTpJK9r/vVMw5WJFGLDlilIDP1hQS2rs4Hsxd094hN7 87I2VIHz3Xc/i+MvVAOmH5NN/hcqY5WSgCcgULgEZOZYIPO7zMc76H/jd8fEsc275d ad3WSTyGpL6d5Y+/S+98C/z3K8OqelJ0im0IiFtRWyMu8N9nDL4uUJX0fQLlP2vvoP hg4KVAHv8LAfQ== From: Tamir Duberstein Date: Tue, 26 May 2026 14:39:11 -0400 Subject: [PATCH v2 5/5] rust: binder: enable `clippy::cast_lossless` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260526-binder-strict-provenance-v2-5-a41d89c29bc5@kernel.org> References: <20260526-binder-strict-provenance-v2-0-a41d89c29bc5@kernel.org> In-Reply-To: <20260526-binder-strict-provenance-v2-0-a41d89c29bc5@kernel.org> To: Greg Kroah-Hartman , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas , Alice Ryhl , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich Cc: Tamir Duberstein , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3051; i=tamird@kernel.org; h=from:subject:message-id; bh=kUy0AxwEksMj1GYxf8Qm6ShYGRejtRREh+yzuoHwPCI=; b=owGbwMvMwCV2wYdPVfy60HTG02pJDFmiLy6oOefnVp4VMRGRmXPio7PJvPyZiwr3HHhzVEhq/ 8lJ4pNmdkxkYRDjYrAUU2RJFD20Nz319h7ZzHfHYeawMoEMkRZpYAACFga+3MS8UiMdIz1TbUM9 QyMdAx1jBi5OAZjq7L0Mfzjqyn4f27WucvuEU5qWa5dNnlPrGBL3QPWEti37pJ98rfUMf8W7fqx dftLj3amD7n+M1rjPKf+rX9kQxivVbfL3g+jvFg4A X-Developer-Key: i=tamird@kernel.org; a=openpgp; fpr=5A6714204D41EC844C50273C19D6FF6092365380 Before Rust 1.29.0, Clippy introduced the `cast_lossless` lint [1]: > Rust's `as` keyword will perform many kinds of conversions, including > silently lossy conversions. Conversion functions such as `i32::from` > will only perform lossless conversions. Using the conversion functions > prevents conversions from becoming silently lossy if the input types > ever change, and makes it clear for people reading the code that the > conversion is lossless. 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#cast_lossle= ss [1] Reviewed-by: Alice Ryhl Assisted-by: Codex:gpt-5 Signed-off-by: Tamir Duberstein --- drivers/android/binder/freeze.rs | 2 +- drivers/android/binder/process.rs | 6 +++--- drivers/android/binder/rust_binder_main.rs | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/android/binder/freeze.rs b/drivers/android/binder/free= ze.rs index 53b60035639a..2178258772e5 100644 --- a/drivers/android/binder/freeze.rs +++ b/drivers/android/binder/freeze.rs @@ -127,7 +127,7 @@ fn do_work( } =20 let mut state_info =3D BinderFrozenStateInfo::default(); - state_info.is_frozen =3D is_frozen as u32; + state_info.is_frozen =3D u32::from(is_frozen); state_info.cookie =3D freeze.cookie.0; freeze.is_pending =3D true; freeze.last_is_frozen =3D Some(is_frozen); diff --git a/drivers/android/binder/process.rs b/drivers/android/binder/pro= cess.rs index 935f04eb2981..71c631105344 100644 --- a/drivers/android/binder/process.rs +++ b/drivers/android/binder/process.rs @@ -1521,9 +1521,9 @@ fn get_frozen_status(data: UserSlice) -> Result { found =3D true; let inner =3D proc.inner.lock(); let txns_pending =3D inner.txns_pending_locked(); - info.async_recv |=3D inner.async_recv as u32; - info.sync_recv |=3D inner.sync_recv as u32; - info.sync_recv |=3D (txns_pending as u32) << 1; + info.async_recv |=3D u32::from(inner.async_recv); + info.sync_recv |=3D u32::from(inner.sync_recv); + info.sync_recv |=3D u32::from(txns_pending) << 1; } }); } diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/b= inder/rust_binder_main.rs index 2c10a8cd3d88..432390aab25b 100644 --- a/drivers/android/binder/rust_binder_main.rs +++ b/drivers/android/binder/rust_binder_main.rs @@ -6,7 +6,6 @@ =20 #![crate_name =3D "rust_binder"] #![recursion_limit =3D "256"] -#![allow(clippy::cast_lossless)] =20 use kernel::{ bindings::{self, seq_file}, --=20 2.54.0