]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: enable `clippy::as_ptr_cast_mut` lint
authorTamir Duberstein <tamird@gmail.com>
Sun, 15 Jun 2025 20:55:07 +0000 (16:55 -0400)
committerMiguel Ojeda <ojeda@kernel.org>
Sun, 22 Jun 2025 21:09:09 +0000 (23:09 +0200)
In Rust 1.66.0, Clippy introduced the `as_ptr_cast_mut` lint [1]:

> Since `as_ptr` takes a `&self`, the pointer won’t have write
> permissions unless interior mutability is used, making it unlikely
> that having it as a mutable pointer is correct.

There is only one affected callsite, and the change amounts to replacing
`as _` with `.cast_mut().cast()`. This doesn't change the semantics, but
is more descriptive of what's going on.

Apply this change and enable the lint -- no functional change intended.

Link: https://rust-lang.github.io/rust-clippy/master/index.html#as_ptr_cast_mut
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/r/20250615-ptr-as-ptr-v12-3-f43b024581e8@gmail.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Makefile
rust/kernel/devres.rs

index 63b705d996319671eee2640d1b08c80b98a7744f..54160d6bb168b2bfe9774b83f769f70deb55cd5b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -479,6 +479,7 @@ export rust_common_flags := --edition=2021 \
                            -Wrust_2018_idioms \
                            -Wunreachable_pub \
                            -Wclippy::all \
+                           -Wclippy::as_ptr_cast_mut \
                            -Wclippy::ignored_unit_patterns \
                            -Wclippy::mut_mut \
                            -Wclippy::needless_bitwise_bool \
index b8ba5417337b13a393f4aa0166afb285a93f2482..b418cfc6f90d863730332b01d5ac25ac9d58a6c9 100644 (file)
@@ -143,7 +143,7 @@ impl<T> DevresInner<T> {
             bindings::devm_remove_action_nowarn(
                 this.dev.as_raw(),
                 Some(this.callback),
-                this.as_ptr() as _,
+                this.as_ptr().cast_mut().cast(),
             )
         } == 0;