All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] rust: replace `allow(...)` with `expect(...)`
@ 2025-06-26 10:04 Onur Özkan
  2025-06-26 10:04 ` [PATCH 1/2] replace `#[allow(...)]` with `#[expect(...)]` Onur Özkan
  2025-06-26 10:04 ` [PATCH 2/2] rust: drop unnecessary lints caught by `#[expect(...)]` Onur Özkan
  0 siblings, 2 replies; 5+ messages in thread
From: Onur Özkan @ 2025-06-26 10:04 UTC (permalink / raw)
  To: linux-kernel, linux-pm, linux-kselftest, kunit-dev
  Cc: airlied, simona, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh,
	lossin, a.hindborg, aliceryhl, tmgross, rafael, viresh.kumar,
	gregkh, maarten.lankhorst, mripard, tzimmermann, davidgow, nm,
	Onur Özkan

Replaces various `#[allow(...)]` with `#[expect(...)]` as suggested
in the kernel coding guidelines: [link]

[link]: https://docs.kernel.org/rust/coding-guidelines.html#lints

After switching to `#[expect(...)]`, I found some dead linting rules
that are no longer needed which are removed in the second patch.

Onur Özkan (1):
  replace `#[allow(...)]` with `#[expect(...)]`

onur-ozkan (1):
  rust: drop unnecessary lints caught by `#[expect(...)]`

 drivers/gpu/nova-core/regs.rs       | 2 +-
 rust/compiler_builtins.rs           | 2 +-
 rust/kernel/alloc/allocator_test.rs | 2 +-
 rust/kernel/cpufreq.rs              | 1 -
 rust/kernel/devres.rs               | 2 +-
 rust/kernel/driver.rs               | 2 +-
 rust/kernel/drm/ioctl.rs            | 8 ++++----
 rust/kernel/error.rs                | 3 +--
 rust/kernel/init.rs                 | 6 +++---
 rust/kernel/kunit.rs                | 2 +-
 rust/kernel/opp.rs                  | 4 ++--
 rust/kernel/types.rs                | 2 +-
 rust/macros/helpers.rs              | 2 +-
 13 files changed, 18 insertions(+), 20 deletions(-)

-- 
2.50.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] replace `#[allow(...)]` with `#[expect(...)]`
  2025-06-26 10:04 [PATCH 0/2] rust: replace `allow(...)` with `expect(...)` Onur Özkan
@ 2025-06-26 10:04 ` Onur Özkan
  2025-06-26 10:04 ` [PATCH 2/2] rust: drop unnecessary lints caught by `#[expect(...)]` Onur Özkan
  1 sibling, 0 replies; 5+ messages in thread
From: Onur Özkan @ 2025-06-26 10:04 UTC (permalink / raw)
  To: linux-kernel, linux-pm, linux-kselftest, kunit-dev
  Cc: airlied, simona, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh,
	lossin, a.hindborg, aliceryhl, tmgross, rafael, viresh.kumar,
	gregkh, maarten.lankhorst, mripard, tzimmermann, davidgow, nm,
	Onur Özkan

This makes it clear that the warning is expected not just
ignored, so we don't end up having various unnecessary
linting rules in the codebase.

Some parts of the codebase already use this approach, this
patch just applies it more broadly.

Signed-off-by: Onur Özkan <work@onurozkan.dev>
---
 drivers/gpu/nova-core/regs.rs       | 2 +-
 rust/compiler_builtins.rs           | 2 +-
 rust/kernel/alloc/allocator_test.rs | 2 +-
 rust/kernel/cpufreq.rs              | 2 +-
 rust/kernel/devres.rs               | 2 +-
 rust/kernel/driver.rs               | 2 +-
 rust/kernel/drm/ioctl.rs            | 8 ++++----
 rust/kernel/error.rs                | 4 ++--
 rust/kernel/init.rs                 | 6 +++---
 rust/kernel/kunit.rs                | 2 +-
 rust/kernel/opp.rs                  | 4 ++--
 rust/kernel/types.rs                | 2 +-
 rust/macros/helpers.rs              | 2 +-
 13 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/nova-core/regs.rs b/drivers/gpu/nova-core/regs.rs
index 5a1273230306..87e5963f1ebb 100644
--- a/drivers/gpu/nova-core/regs.rs
+++ b/drivers/gpu/nova-core/regs.rs
@@ -2,7 +2,7 @@
 
 // Required to retain the original register names used by OpenRM, which are all capital snake case
 // but are mapped to types.
-#![allow(non_camel_case_types)]
+#![expect(non_camel_case_types)]
 
 #[macro_use]
 mod macros;
diff --git a/rust/compiler_builtins.rs b/rust/compiler_builtins.rs
index dd16c1dc899c..477b41da56d7 100644
--- a/rust/compiler_builtins.rs
+++ b/rust/compiler_builtins.rs
@@ -19,7 +19,7 @@
 //! [`compiler_builtins`]: https://github.com/rust-lang/compiler-builtins
 //! [`compiler-rt`]: https://compiler-rt.llvm.org/
 
-#![allow(internal_features)]
+#![expect(internal_features)]
 #![feature(compiler_builtins)]
 #![compiler_builtins]
 #![no_builtins]
diff --git a/rust/kernel/alloc/allocator_test.rs b/rust/kernel/alloc/allocator_test.rs
index d19c06ef0498..844197d7194e 100644
--- a/rust/kernel/alloc/allocator_test.rs
+++ b/rust/kernel/alloc/allocator_test.rs
@@ -7,7 +7,7 @@
 //! `Cmalloc` allocator within the `allocator_test` module and type alias all kernel allocators to
 //! `Cmalloc`. The `Cmalloc` allocator uses libc's `realloc()` function as allocator backend.
 
-#![allow(missing_docs)]
+#![expect(missing_docs)]
 
 use super::{flags::*, AllocError, Allocator, Flags};
 use core::alloc::Layout;
diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs
index 11b03e9d7e89..7b20dff23a68 100644
--- a/rust/kernel/cpufreq.rs
+++ b/rust/kernel/cpufreq.rs
@@ -907,7 +907,7 @@ fn register_em(_policy: &mut Policy) {
 /// or CPUs, so it is safe to share it.
 unsafe impl<T: Driver> Sync for Registration<T> {}
 
-#[allow(clippy::non_send_fields_in_send_ty)]
+#[expect(clippy::non_send_fields_in_send_ty)]
 /// SAFETY: Registration with and unregistration from the cpufreq subsystem can happen from any
 /// thread.
 unsafe impl<T: Driver> Send for Registration<T> {}
diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs
index 57502534d985..0e9510cf4625 100644
--- a/rust/kernel/devres.rs
+++ b/rust/kernel/devres.rs
@@ -157,7 +157,7 @@ fn remove_action(this: &Arc<Self>) -> bool {
         success
     }
 
-    #[allow(clippy::missing_safety_doc)]
+    #[expect(clippy::missing_safety_doc)]
     unsafe extern "C" fn devres_callback(ptr: *mut kernel::ffi::c_void) {
         let ptr = ptr as *mut DevresInner<T>;
         // Devres owned this memory; now that we received the callback, drop the `Arc` and hence the
diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs
index ec9166cedfa7..fc7bd65b01f1 100644
--- a/rust/kernel/driver.rs
+++ b/rust/kernel/driver.rs
@@ -168,7 +168,7 @@ fn of_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
     }
 
     #[cfg(not(CONFIG_OF))]
-    #[allow(missing_docs)]
+    #[expect(missing_docs)]
     fn of_id_info(_dev: &device::Device) -> Option<&'static Self::IdInfo> {
         None
     }
diff --git a/rust/kernel/drm/ioctl.rs b/rust/kernel/drm/ioctl.rs
index 445639404fb7..3ae8d2d8263f 100644
--- a/rust/kernel/drm/ioctl.rs
+++ b/rust/kernel/drm/ioctl.rs
@@ -9,28 +9,28 @@
 const BASE: u32 = uapi::DRM_IOCTL_BASE as u32;
 
 /// Construct a DRM ioctl number with no argument.
-#[allow(non_snake_case)]
+#[expect(non_snake_case)]
 #[inline(always)]
 pub const fn IO(nr: u32) -> u32 {
     ioctl::_IO(BASE, nr)
 }
 
 /// Construct a DRM ioctl number with a read-only argument.
-#[allow(non_snake_case)]
+#[expect(non_snake_case)]
 #[inline(always)]
 pub const fn IOR<T>(nr: u32) -> u32 {
     ioctl::_IOR::<T>(BASE, nr)
 }
 
 /// Construct a DRM ioctl number with a write-only argument.
-#[allow(non_snake_case)]
+#[expect(non_snake_case)]
 #[inline(always)]
 pub const fn IOW<T>(nr: u32) -> u32 {
     ioctl::_IOW::<T>(BASE, nr)
 }
 
 /// Construct a DRM ioctl number with a read-write argument.
-#[allow(non_snake_case)]
+#[expect(non_snake_case)]
 #[inline(always)]
 pub const fn IOWR<T>(nr: u32) -> u32 {
     ioctl::_IOWR::<T>(BASE, nr)
diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
index 3dee3139fcd4..1ff2d57c2f14 100644
--- a/rust/kernel/error.rs
+++ b/rust/kernel/error.rs
@@ -263,7 +263,7 @@ fn from(e: core::convert::Infallible) -> Error {
 /// [`samples/rust/rust_minimal.rs`]):
 ///
 /// ```
-/// # #[allow(clippy::single_match)]
+/// # #[expect(clippy::single_match)]
 /// fn example() -> Result {
 ///     let mut numbers = KVec::new();
 ///
@@ -413,7 +413,7 @@ pub fn from_err_ptr<T>(ptr: *mut T) -> Result<*mut T> {
         // SAFETY: The FFI function does not deref the pointer.
         let err = unsafe { bindings::PTR_ERR(const_ptr) };
 
-        #[allow(clippy::unnecessary_cast)]
+        #[expect(clippy::unnecessary_cast)]
         // CAST: If `IS_ERR()` returns `true`,
         // then `PTR_ERR()` is guaranteed to return a
         // negative value greater-or-equal to `-bindings::MAX_ERRNO`,
diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs
index 8d228c237954..288b1c2a290d 100644
--- a/rust/kernel/init.rs
+++ b/rust/kernel/init.rs
@@ -30,7 +30,7 @@
 //! ## General Examples
 //!
 //! ```rust,ignore
-//! # #![allow(clippy::disallowed_names)]
+//! # #![expect(clippy::disallowed_names)]
 //! use kernel::types::Opaque;
 //! use pin_init::pin_init_from_closure;
 //!
@@ -67,11 +67,11 @@
 //! ```
 //!
 //! ```rust,ignore
-//! # #![allow(unreachable_pub, clippy::disallowed_names)]
+//! # #![expect(unreachable_pub, clippy::disallowed_names)]
 //! use kernel::{prelude::*, types::Opaque};
 //! use core::{ptr::addr_of_mut, marker::PhantomPinned, pin::Pin};
 //! # mod bindings {
-//! #     #![allow(non_camel_case_types)]
+//! #     #![expect(non_camel_case_types)]
 //! #     pub struct foo;
 //! #     pub unsafe fn init_foo(_ptr: *mut foo) {}
 //! #     pub unsafe fn destroy_foo(_ptr: *mut foo) {}
diff --git a/rust/kernel/kunit.rs b/rust/kernel/kunit.rs
index 4b8cdcb21e77..91710a1d7b87 100644
--- a/rust/kernel/kunit.rs
+++ b/rust/kernel/kunit.rs
@@ -280,7 +280,7 @@ macro_rules! kunit_unsafe_test_suite {
             static mut KUNIT_TEST_SUITE: ::kernel::bindings::kunit_suite =
                 ::kernel::bindings::kunit_suite {
                     name: KUNIT_TEST_SUITE_NAME,
-                    #[allow(unused_unsafe)]
+                    #[expect(unused_unsafe)]
                     // SAFETY: `$test_cases` is passed in by the user, and
                     // (as documented) must be valid for the lifetime of
                     // the suite (i.e., static).
diff --git a/rust/kernel/opp.rs b/rust/kernel/opp.rs
index a566fc3e7dcb..aaeefe84861a 100644
--- a/rust/kernel/opp.rs
+++ b/rust/kernel/opp.rs
@@ -600,9 +600,9 @@ extern "C" fn config_regulators(
 pub struct Table {
     ptr: *mut bindings::opp_table,
     dev: ARef<Device>,
-    #[allow(dead_code)]
+    #[expect(dead_code)]
     em: bool,
-    #[allow(dead_code)]
+    #[expect(dead_code)]
     of: bool,
     cpus: Option<CpumaskVar>,
 }
diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
index 22985b6f6982..a5d5a4737a41 100644
--- a/rust/kernel/types.rs
+++ b/rust/kernel/types.rs
@@ -600,5 +600,5 @@ pub enum Either<L, R> {
 /// constructed.
 ///
 /// [`NotThreadSafe`]: type@NotThreadSafe
-#[allow(non_upper_case_globals)]
+#[expect(non_upper_case_globals)]
 pub const NotThreadSafe: NotThreadSafe = PhantomData;
diff --git a/rust/macros/helpers.rs b/rust/macros/helpers.rs
index e2602be402c1..6fd1462ff01a 100644
--- a/rust/macros/helpers.rs
+++ b/rust/macros/helpers.rs
@@ -98,7 +98,7 @@ pub(crate) fn file() -> String {
     }
 
     #[cfg(CONFIG_RUSTC_HAS_SPAN_FILE)]
-    #[allow(clippy::incompatible_msrv)]
+    #[expect(clippy::incompatible_msrv)]
     {
         proc_macro::Span::call_site().file()
     }
-- 
2.50.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] rust: drop unnecessary lints caught by `#[expect(...)]`
  2025-06-26 10:04 [PATCH 0/2] rust: replace `allow(...)` with `expect(...)` Onur Özkan
  2025-06-26 10:04 ` [PATCH 1/2] replace `#[allow(...)]` with `#[expect(...)]` Onur Özkan
@ 2025-06-26 10:04 ` Onur Özkan
  2025-06-26 10:09   ` Onur
  2025-06-26 11:50   ` Miguel Ojeda
  1 sibling, 2 replies; 5+ messages in thread
From: Onur Özkan @ 2025-06-26 10:04 UTC (permalink / raw)
  To: linux-kernel, linux-pm, linux-kselftest, kunit-dev
  Cc: airlied, simona, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh,
	lossin, a.hindborg, aliceryhl, tmgross, rafael, viresh.kumar,
	gregkh, maarten.lankhorst, mripard, tzimmermann, davidgow, nm,
	onur-ozkan

From: onur-ozkan <work@onurozkan.dev>

They are no longer needed.

Signed-off-by: onur-ozkan <work@onurozkan.dev>
---
 rust/kernel/cpufreq.rs | 1 -
 rust/kernel/error.rs   | 1 -
 2 files changed, 2 deletions(-)

diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs
index 7b20dff23a68..97de9b0573da 100644
--- a/rust/kernel/cpufreq.rs
+++ b/rust/kernel/cpufreq.rs
@@ -907,7 +907,6 @@ fn register_em(_policy: &mut Policy) {
 /// or CPUs, so it is safe to share it.
 unsafe impl<T: Driver> Sync for Registration<T> {}
 
-#[expect(clippy::non_send_fields_in_send_ty)]
 /// SAFETY: Registration with and unregistration from the cpufreq subsystem can happen from any
 /// thread.
 unsafe impl<T: Driver> Send for Registration<T> {}
diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
index 1ff2d57c2f14..05c6e71c0afb 100644
--- a/rust/kernel/error.rs
+++ b/rust/kernel/error.rs
@@ -413,7 +413,6 @@ pub fn from_err_ptr<T>(ptr: *mut T) -> Result<*mut T> {
         // SAFETY: The FFI function does not deref the pointer.
         let err = unsafe { bindings::PTR_ERR(const_ptr) };
 
-        #[expect(clippy::unnecessary_cast)]
         // CAST: If `IS_ERR()` returns `true`,
         // then `PTR_ERR()` is guaranteed to return a
         // negative value greater-or-equal to `-bindings::MAX_ERRNO`,
-- 
2.50.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] rust: drop unnecessary lints caught by `#[expect(...)]`
  2025-06-26 10:04 ` [PATCH 2/2] rust: drop unnecessary lints caught by `#[expect(...)]` Onur Özkan
@ 2025-06-26 10:09   ` Onur
  2025-06-26 11:50   ` Miguel Ojeda
  1 sibling, 0 replies; 5+ messages in thread
From: Onur @ 2025-06-26 10:09 UTC (permalink / raw)
  To: linux-kernel, linux-pm, linux-kselftest, kunit-dev
  Cc: airlied, simona, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh,
	lossin, a.hindborg, aliceryhl, tmgross, rafael, viresh.kumar,
	gregkh, maarten.lankhorst, mripard, tzimmermann, davidgow, nm

On Thu, 26 Jun 2025 13:04:48 +0300
Onur Özkan <work@onurozkan.dev> wrote:

> From: onur-ozkan <work@onurozkan.dev>
> 
> They are no longer needed.
> 
> Signed-off-by: onur-ozkan <work@onurozkan.dev>

Oh crap... This should be "Onur Özkan" not "onur-ozkan".
I forgot to update that in my 2nd computer, which was used
to send this patch.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] rust: drop unnecessary lints caught by `#[expect(...)]`
  2025-06-26 10:04 ` [PATCH 2/2] rust: drop unnecessary lints caught by `#[expect(...)]` Onur Özkan
  2025-06-26 10:09   ` Onur
@ 2025-06-26 11:50   ` Miguel Ojeda
  1 sibling, 0 replies; 5+ messages in thread
From: Miguel Ojeda @ 2025-06-26 11:50 UTC (permalink / raw)
  To: Onur Özkan
  Cc: linux-kernel, linux-pm, linux-kselftest, kunit-dev, airlied,
	simona, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh, lossin,
	a.hindborg, aliceryhl, tmgross, rafael, viresh.kumar, gregkh,
	maarten.lankhorst, mripard, tzimmermann, davidgow, nm

On Thu, Jun 26, 2025 at 12:06 PM Onur Özkan <work@onurozkan.dev> wrote:
>
> -        #[expect(clippy::unnecessary_cast)]

We should avoid converting them into `expect` in the previous patch,
because then it would break the build between the commits (it is not
too critical if it is a Clippy one, but we still aim to keep builds
Clippy clean).

In addition, the reasoning for each of these not being needed may not
be immediately obvious (unlike other lint patches that follow all a
pattern). So it would be best to split the patches into cases to
explain each. For instance, this one is because with the new custom
FFI mappings `c_long` is always `isize` now, which is always different
from `c_int` (`i32`).

By the way, please Cc the rust-for-linux list too.

Thanks!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-06-26 11:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-26 10:04 [PATCH 0/2] rust: replace `allow(...)` with `expect(...)` Onur Özkan
2025-06-26 10:04 ` [PATCH 1/2] replace `#[allow(...)]` with `#[expect(...)]` Onur Özkan
2025-06-26 10:04 ` [PATCH 2/2] rust: drop unnecessary lints caught by `#[expect(...)]` Onur Özkan
2025-06-26 10:09   ` Onur
2025-06-26 11:50   ` Miguel Ojeda

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.