Skip to contentSkip to conversation

Remove redundant imports of items re-exported from prelude

PATCH Applied Gary Guo 8 participants 20 messages Jan 23 – Jan 30

Subsystems (9)
lore
Share & tools
lore

Gary Guo

author reviewer
#0 lore raw

cover Remove redundant imports of items re-exported from prelude

We had a few occurrence of these redundant imports and up until now they're mostly checked by human reviews.

I have now implemented a new lint in klint, which is able to spot these and advice on using prelude imports instead. It caught a few existing cases that slip through the review. Thus, fix them.

Gary Guo (3):
gpu: nova-core: remove imports available via prelude
block: rnull: remove imports available via prelude
samples: rust: remove imports available via prelude

 drivers/block/rnull/configfs.rs         |  1 -
 drivers/block/rnull/rnull.rs            |  3 ---
 drivers/gpu/nova-core/firmware/fwsec.rs |  1 -
 drivers/gpu/nova-core/firmware/gsp.rs   | 12 +++++-------
 drivers/gpu/nova-core/firmware/riscv.rs |  2 --
 drivers/gpu/nova-core/gsp/sequencer.rs  |  8 +-------
 drivers/gpu/nova-core/sbuffer.rs        |  5 +----
 samples/rust/rust_driver_auxiliary.rs   |  1 -
 samples/rust/rust_misc_device.rs        |  2 --
 samples/rust/rust_print_main.rs         |  2 +-
 10 files changed, 8 insertions(+), 29 deletions(-)

base-commit: a0c666c25aeefd16f4b088c6549a6fb6b65a8a1d

Signature · 1 line
2.51.2
author reviewer
#1 lore raw

PATCH 1/3 gpu: nova-core: remove imports available via prelude

These imports are already in scope by importing kernel::prelude::* and does not need to be imported separately.

---
 drivers/gpu/nova-core/firmware/fwsec.rs |  1 -
 drivers/gpu/nova-core/firmware/gsp.rs   | 12 +++++-------
 drivers/gpu/nova-core/firmware/riscv.rs |  2 --
 drivers/gpu/nova-core/gsp/sequencer.rs  |  8 +-------
 drivers/gpu/nova-core/sbuffer.rs        |  5 +----
 5 files changed, 7 insertions(+), 21 deletions(-)
drivers/gpu/nova-core/firmware/fwsec.rs +0 -1
index b28e34d279f4..dd2d1f0f24ed 100644
@@ -12,7 +12,6 @@
 
 use core::{
     marker::PhantomData,
-    mem::size_of,
     ops::Deref, //
 };
 
drivers/gpu/nova-core/firmware/gsp.rs +5 -7
index 1025b7f746eb..f0f18166849e 100644
@@ -1,7 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
 
-use core::mem::size_of_val;
-
 use kernel::{
     device,
     dma::{
@@ -34,11 +32,11 @@
 /// that scheme before nova-core becomes stable, which means this module will eventually be
 /// removed.
 mod elf {
-    use core::mem::size_of;
-
-    use kernel::bindings;
-    use kernel::str::CStr;
-    use kernel::transmute::FromBytes;
+    use kernel::{
+        bindings,
+        prelude::*,
+        transmute::FromBytes, //
+    };
 
     /// Newtype to provide a [`FromBytes`] implementation.
     #[repr(transparent)]
drivers/gpu/nova-core/firmware/riscv.rs +0 -2
index 28dfef63657a..4bdd89bd0757 100644
@@ -3,8 +3,6 @@
 //! Support for firmware binaries designed to run on a RISC-V core. Such firmwares files have a
 //! dedicated header.
 
-use core::mem::size_of;
-
 use kernel::{
     device,
     firmware::Firmware,
drivers/gpu/nova-core/gsp/sequencer.rs +1 -7
index d6c489c39092..c31b245acea3 100644
@@ -2,13 +2,7 @@
 
 //! GSP Sequencer implementation for Pre-hopper GSP boot sequence.
 
-use core::{
-    array,
-    mem::{
-        size_of,
-        size_of_val, //
-    },
-};
+use core::array;
 
 use kernel::{
     device,
drivers/gpu/nova-core/sbuffer.rs +1 -4
index 64758b7fae56..3a41d224c77a 100644
@@ -2,10 +2,7 @@
 
 use core::ops::Deref;
 
-use kernel::{
-    alloc::KVec,
-    prelude::*, //
-};
+use kernel::prelude::*;
 
 /// A buffer abstraction for discontiguous byte slices.
 ///
Signature · 1 line
2.51.2
maintainer
#2 lore raw

Re: [PATCH 1/3] gpu: nova-core: remove imports available via prelude

Quoted 4 lines · Gary Guo

These imports are already in scope by importing kernel::prelude::* and does not need to be imported separately.

I will pick this one up after -rc1 is out.

maintainer Acked-by
#3 lore raw

Re: [PATCH 1/3] gpu: nova-core: remove imports available via prelude

Quoted 1 line · Danilo Krummrich

I will pick this one up after -rc1 is out.

I just checked and there shouldn't be any conflicts, so if you want to pick this one up as well, please do. :)

Given that klint can do quite some convinient extra checks, should we consider making it an optional part of the build? Similar to what we do with clippy?

#4 lore raw

Re: [PATCH 1/3] gpu: nova-core: remove imports available via prelude

Quoted 5 lines · Danilo Krummrich

I just checked and there shouldn't be any conflicts, so if you want to pick this one up as well, please do. :)

Will, do thanks!

Quoted 2 lines

Given that klint can do quite some convinient extra checks, should we consider making it an optional part of the build? Similar to what we do with clippy?

Yeah, that is the goal (e.g. KLINT=1 or similar eventually).

But if someone wants to run it, it is already possible, IIUC Andreas already did the other day.

To make things easier for developers/maintainers, I asked Nathan the other day if we could have them in the LLVM+Rust kernel.org toolchains, and he was supportive on adding it there when Gary is ready, so it may be straightforward to set up in CIs! :)

(And later on, ideally, even on linux-next when we things are more settled)

Cheers,
Miguel

Applied
#5 lore raw

Re: [PATCH 1/3] gpu: nova-core: remove imports available via prelude

In reply to Gary Guo
Quoted 5 lines · Gary Guo

These imports are already in scope by importing kernel::prelude::* and does not need to be imported separately.

Applied to rust-next -- thanks everyone!

With this last one done, this series has all been applied.

Cheers,
Miguel

author reviewer
#6 lore raw

PATCH 2/3 block: rnull: remove imports available via prelude

In reply to Gary Guo

These imports are already in scope by importing kernel::prelude::* and does not need to be imported separately.

---
 drivers/block/rnull/configfs.rs | 1 -
 drivers/block/rnull/rnull.rs    | 3 ---
 2 files changed, 4 deletions(-)
drivers/block/rnull/configfs.rs +0 -1
index bfe998d31eb9..7c2eb5c0b722 100644
@@ -12,7 +12,6 @@
     str::{kstrtobool_bytes, CString},
     sync::Mutex,
 };
-use pin_init::PinInit;
 
 pub(crate) fn subsystem() -> impl PinInit<kernel::configfs::Subsystem<Config>, Error> {
     let item_type = configfs_attrs! {
drivers/block/rnull/rnull.rs +0 -3
index a9d5e575a2c4..0ca8715febe8 100644
@@ -14,12 +14,9 @@
             Operations, TagSet,
         },
     },
-    error::Result,
-    pr_info,
     prelude::*,
     sync::{aref::ARef, Arc},
 };
-use pin_init::PinInit;
 
 module! {
     type: NullBlkModule,
Signature · 1 line
2.51.2
maintainer
#9 lore raw

Re: [PATCH 2/3] block: rnull: remove imports available via prelude

Quoted 5 lines · Miguel Ojeda
Quoted 2 lines · Andreas Hindborg

Is this for Jens or do you want me to pick it up?

I think Jens is supposed to pick the block patches.

Best regards,
Andreas Hindborg

author reviewer
#10 lore raw

PATCH 3/3 samples: rust: remove imports available via prelude

In reply to Gary Guo

These imports are already in scope by importing kernel::prelude::* and does not need to be imported separately.

---
 samples/rust/rust_driver_auxiliary.rs | 1 -
 samples/rust/rust_misc_device.rs      | 2 --
 samples/rust/rust_print_main.rs       | 2 +-
 3 files changed, 1 insertion(+), 4 deletions(-)
samples/rust/rust_driver_auxiliary.rs +0 -1
index f148124fe81f..84c2b1045701 100644
@@ -18,7 +18,6 @@
 };
 
 use core::any::TypeId;
-use pin_init::PinInit;
 
 const MODULE_NAME: &CStr = <LocalModule as kernel::ModuleMetadata>::NAME;
 const AUXILIARY_NAME: &CStr = c"auxiliary";
samples/rust/rust_misc_device.rs +0 -2
index 49dd5814e1ab..87a1fe63533a 100644
@@ -95,8 +95,6 @@
 //! }
 //! ```
 
-use core::pin::Pin;
-
 use kernel::{
     device::Device,
     fs::{File, Kiocb},
samples/rust/rust_print_main.rs +1 -1
index 4095c72afeab..682207c81fc2 100644
@@ -101,7 +101,7 @@ fn drop(&mut self) {
 }
 
 mod trace {
-    use kernel::ffi::c_int;
+    use kernel::prelude::*;
 
     kernel::declare_trace! {
         /// # Safety
Signature · 1 line
2.51.2
#13 lore raw

Re: [PATCH 3/3] samples: rust: remove imports available via prelude

In reply to Gary Guo
Quoted 2 lines · Gary Guo
  samples/rust/rust_misc_device.rs      | 2 --

If Greg/Arnd don't say otherwise, I will eventually pick this patch including the file above, given it is trivial.

Cheers,
Miguel

maintainer Acked-by
#14 lore raw

Re: [PATCH 3/3] samples: rust: remove imports available via prelude

Quoted 6 lines · Miguel Ojeda
Quoted 2 lines · Gary Guo
  samples/rust/rust_misc_device.rs      | 2 --

If Greg/Arnd don't say otherwise, I will eventually pick this patch including the file above, given it is trivial.

No objection from me:

#15 lore raw

Re: [PATCH 3/3] samples: rust: remove imports available via prelude

In reply to Gary Guo
Quoted 5 lines · Gary Guo

These imports are already in scope by importing kernel::prelude::* and does not need to be imported separately.

Applied (this one only) to rust-next -- thanks everyone!

Cheers,
Miguel

#16 lore raw

Re: [PATCH 3/3] samples: rust: remove imports available via prelude

Quoted 8 lines · Miguel Ojeda
Quoted 5 lines · Gary Guo

These imports are already in scope by importing kernel::prelude::* and does not need to be imported separately.

Applied (this one only) to rust-next -- thanks everyone!

Having my klint setup running now (many thanks Gary!) on today's rust-next [1] I still get

error: this item is available via prelude
--> samples/rust/rust_driver_auxiliary.rs:12:5

   |
12 |     error::Error,
   |     ^^^^^^^^^^^^
   |

= help: import with kernel::prelude::* instead
= note: -D klint::not-using-prelude implied by -D warnings = help: to override -D warnings add
#[allow(klint::not_using_prelude)]

error: aborting due to 1 previous error

Somehow dropping this was not part of this patch. Not sure why ...

Best regards

Dirk

[1] HEAD is 08afcc38a64c ("Merge patch series "Add support for print exactly once"")

author reviewer
#17 lore raw

Re: [PATCH 3/3] samples: rust: remove imports available via prelude

Quoted 24 lines · Dirk Behme
Quoted 8 lines · Miguel Ojeda
Quoted 5 lines · Gary Guo

These imports are already in scope by importing kernel::prelude::* and does not need to be imported separately.

Applied (this one only) to rust-next -- thanks everyone!

Having my klint setup running now (many thanks Gary!) on today's rust-next [1] I still get

error: this item is available via prelude
--> samples/rust/rust_driver_auxiliary.rs:12:5

    |

12 | error::Error,
| ^^^^^^^^^^^^
|
= help: import with kernel::prelude::* instead
= note: -D klint::not-using-prelude implied by -D warnings = help: to override -D warnings add
#[allow(klint::not_using_prelude)]

Quoted 3 lines

error: aborting due to 1 previous error

Somehow dropping this was not part of this patch. Not sure why ...

It was already dropped in
https://lore.kernel.org/rust-for-linux/[email protected]/

Best,
Gary

Quoted 7 lines

Best regards

Dirk

[1] HEAD is 08afcc38a64c ("Merge patch series "Add support for print exactly once"")

#18 lore raw
In reply to Gary Guo
Quoted 9 lines · Gary Guo

We had a few occurrence of these redundant imports and up until now they're mostly checked by human reviews.

I have now implemented a new lint in klint, which is able to spot these and advice on using prelude imports instead. It caught a few existing cases that slip through the review. Thus, fix them.

This is great news, thanks Gary.

If others give Acked-bys, I can pick these all, but it may be easier to pick them independently (for that, the print sample should be split in principle, but it is so small that Acked-bys may work better for that last patch).

Cheers,
Miguel

maintainer Applied
#19 lore raw

Re: (subset) [PATCH 0/3] Remove redundant imports of items re-exported from prelude

In reply to Gary Guo
Quoted 8 lines · Gary Guo

We had a few occurrence of these redundant imports and up until now they're mostly checked by human reviews.

I have now implemented a new lint in klint, which is able to spot these and advice on using prelude imports instead. It caught a few existing cases that slip through the review. Thus, fix them.

[...]

Applied, thanks!

[2/3] block: rnull: remove imports available via prelude

      commit: b2b2ce870651db659247f34636e6243b4547e8af

Best regards,

Signature · 1 line
Jens Axboe