[PATCH v2 5/5] rust: binder: enable `clippy::cast_lossless`

From: Tamir Duberstein

Date: Tue May 26 2026 - 14:40:24 EST


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_lossless [1]
Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Assisted-by: Codex:gpt-5
Signed-off-by: Tamir Duberstein <tamird@xxxxxxxxxx>
---
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/freeze.rs
index 53b60035639a..2178258772e5 100644
--- a/drivers/android/binder/freeze.rs
+++ b/drivers/android/binder/freeze.rs
@@ -127,7 +127,7 @@ fn do_work(
}

let mut state_info = BinderFrozenStateInfo::default();
- state_info.is_frozen = is_frozen as u32;
+ state_info.is_frozen = u32::from(is_frozen);
state_info.cookie = freeze.cookie.0;
freeze.is_pending = true;
freeze.last_is_frozen = Some(is_frozen);
diff --git a/drivers/android/binder/process.rs b/drivers/android/binder/process.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 = true;
let inner = proc.inner.lock();
let txns_pending = inner.txns_pending_locked();
- info.async_recv |= inner.async_recv as u32;
- info.sync_recv |= inner.sync_recv as u32;
- info.sync_recv |= (txns_pending as u32) << 1;
+ info.async_recv |= u32::from(inner.async_recv);
+ info.sync_recv |= u32::from(inner.sync_recv);
+ info.sync_recv |= u32::from(txns_pending) << 1;
}
});
}
diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/binder/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 @@

#![crate_name = "rust_binder"]
#![recursion_limit = "256"]
-#![allow(clippy::cast_lossless)]

use kernel::{
bindings::{self, seq_file},

--
2.54.0