mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-28 05:14:41 -04:00
rust: binder: enable clippy::ptr_as_ptr lint
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 <tamird@kernel.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://patch.msgid.link/20260526-binder-strict-provenance-v2-2-a41d89c29bc5@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
32782e3115
commit
7d7b2011e7
@@ -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_transaction_data
|
||||
as *mut BinderTransactionData)
|
||||
&mut *((&mut self.transaction_data as *mut uapi::binder_transaction_data)
|
||||
.cast::<BinderTransactionData>())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user