rust: use vertical import style and remove redundant imports
Subsystems (6)
v3 cover rust: use vertical import style and remove redundant imports
Adopt the vertical import style and drop redundant imports already re-exported via kernel::prelude.
Changes include:
- Convert use statements to vertical import style in miscdevice, samples, doctest, and block/mq
- Remove imports covered by prelude and apply minor formatting
---
Changes in v3:
- Add trailing // to last items and closing braces in block/mq imports
- Add rnull vertical import style
- Add doctest vertical import style
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Reformat use statements and drop redundant imports in
rust/kernel/block/mq
- Drop redundant imports in rust/kernel/miscdevice
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Alvin Sun (7):
rust: miscdevice: use vertical import style
samples: rust_misc_device: use vertical import style
rust: miscdevice: remove redundant imports
rust: block: mq: use vertical import style
rust: block: mq: remove redundant imports and format
rust: block: rnull: use vertical import style
rust: doctest: use vertical import style
drivers/block/rnull/configfs.rs | 27 +++++++++++++++++++++------ drivers/block/rnull/rnull.rs | 15 +++++++++++---- rust/kernel/block/mq/gen_disk.rs | 24 ++++++++++++++++++------ rust/kernel/block/mq/operations.rs | 14 ++++++++++---- rust/kernel/block/mq/request.rs | 16 +++++++++++----- rust/kernel/block/mq/tag_set.rs | 28 ++++++++++++++-------------- rust/kernel/miscdevice.rs | 23 +++++++++++++++++------ samples/rust/rust_misc_device.rs | 34 ++++++++++++++++++++++++++++------ scripts/rustdoc_test_gen.rs | 11 +++++++++-- 9 files changed, 139 insertions(+), 53 deletions(-)
---
base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8
change-id: 20260519-miscdev-use-format-9ab7e83b1c11
Best regards,
Signature · 1 line
Alvin Sun <[email protected]>
PATCH v3 1/7 rust: miscdevice: use vertical import style
Convert use imports to vertical layout for better readability and maintainability.
--- rust/kernel/miscdevice.rs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)
rust/kernel/miscdevice.rs +28 -6
@@ -11,16 +11,38 @@use crate ::{ bindings, device::Device , - error::{to_result,Error ,Result ,VTABLE_DEFAULT_ERROR }, - ffi::{c_int, c_long, c_uint, c_ulong}, - fs::{File ,Kiocb }, - iov::{IovIterDest ,IovIterSource }, + error::{ + to_result, +Error , +Result , +VTABLE_DEFAULT_ERROR ,// + }, + ffi::{ + c_int, + c_long, + c_uint, + c_ulong,// + }, + fs::{ +File , +Kiocb ,// + }, + iov::{ +IovIterDest , +IovIterSource ,// + }, mm::virt::VmaNew , prelude::*, seq_file::SeqFile , - types::{ForeignOwnable ,Opaque }, + types::{ +ForeignOwnable , +Opaque ,// + }, +}; +use core::{ + marker::PhantomData , + pin::Pin ,// }; -use core::{marker::PhantomData , pin::Pin };/// Options for creating a misc device. #[derive( Copy , Clone )]
Signature · 1 line
2.43.0
PATCH v3 2/7 samples: rust_misc_device: use vertical import style
In reply to Alvin SunConvert use imports to vertical layout for better readability and maintainability.
--- samples/rust/rust_misc_device.rs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)
samples/rust/rust_misc_device.rs +28 -6
@@ -97,14 +97,36 @@use kernel::{ device::Device , - fs::{File ,Kiocb }, - ioctl::{_IO, _IOC_SIZE, _IOR, _IOW}, - iov::{IovIterDest ,IovIterSource }, - miscdevice::{MiscDevice ,MiscDeviceOptions ,MiscDeviceRegistration }, + fs::{ +File , +Kiocb ,// + }, + ioctl::{ + _IO, + _IOC_SIZE, + _IOR, + _IOW,// + }, + iov::{ +IovIterDest , +IovIterSource ,// + }, + miscdevice::{ +MiscDevice , +MiscDeviceOptions , +MiscDeviceRegistration ,// + }, new_mutex, prelude::*, - sync::{aref::ARef ,Mutex }, - uaccess::{UserSlice ,UserSliceReader ,UserSliceWriter }, + sync::{ + aref::ARef , +Mutex ,// + }, + uaccess::{ +UserSlice , +UserSliceReader , +UserSliceWriter ,// + }, };const RUST_MISC_DEV_HELLO :u32 =_IO ('|' as u32 ,0x80 );
Signature · 1 line
2.43.0
PATCH v3 3/7 rust: miscdevice: remove redundant imports
In reply to Alvin SunDrop Error, Result, Pin, c_int, c_long, c_uint, and c_ulong imports already provided by kernel::prelude.
--- rust/kernel/miscdevice.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)
rust/kernel/miscdevice.rs +1 -12
@@ -13,16 +13,8 @@ device::Device, error::{ to_result, - Error, - Result, VTABLE_DEFAULT_ERROR, // }, - ffi::{ - c_int, - c_long, - c_uint, - c_ulong, // - }, fs::{File ,Kiocb ,//
@@ -39,10 +31,7 @@ Opaque, // }, }; -use core::{ - marker::PhantomData , - pin::Pin ,// -}; +use core::marker::PhantomData ;/// Options for creating a misc device. #[derive( Copy , Clone )]
Signature · 1 line
2.43.0
PATCH v3 4/7 rust: block: mq: use vertical import style
In reply to Alvin SunConvert use imports to vertical layout for better readability and maintainability.
--- rust/kernel/block/mq/gen_disk.rs | 21 +++++++++++++++++---- rust/kernel/block/mq/operations.rs | 17 +++++++++++++---- rust/kernel/block/mq/request.rs | 14 ++++++++++---- rust/kernel/block/mq/tag_set.rs | 24 +++++++++++++++++++----- 4 files changed, 59 insertions(+), 17 deletions(-)
rust/kernel/block/mq/gen_disk.rs +17 -4
@@ -7,14 +7,27 @@use crate ::{ bindings, - block::mq::{Operations ,TagSet }, - error::{self, from_err_ptr,Result }, - fmt::{self,Write }, + block::mq::{ +Operations , +TagSet ,// + }, + error::{ + self, + from_err_ptr, +Result ,// + }, + fmt::{ + self, +Write ,// + }, prelude::*, static_lock_class, str::NullTerminatedFormatter , sync::Arc , - types::{ForeignOwnable ,ScopeGuard }, + types::{ +ForeignOwnable , +ScopeGuard ,// + },// };/// A builder for [`GenDisk`].
rust/kernel/block/mq/operations.rs +13 -4
@@ -6,11 +6,20 @@use crate ::{ bindings, - block::mq::{request::RequestDataWrapper ,Request }, - error::{from_result,Result }, + block::mq::{ + request::RequestDataWrapper , +Request ,// + }, + error::{ + from_result, +Result ,// + }, prelude::*, - sync::{aref::ARef ,Refcount }, - types::ForeignOwnable , + sync::{ + aref::ARef , +Refcount ,// + }, + types::ForeignOwnable ,// };use core::marker::PhantomData ;
rust/kernel/block/mq/request.rs +10 -4
@@ -9,13 +9,19 @@ block::mq::Operations, error::Result, sync::{ - aref::{ARef, AlwaysRefCounted}, + aref::{ + ARef, + AlwaysRefCounted, // + }, atomic::Relaxed, - Refcount, + Refcount, // }, - types::Opaque, + types::Opaque, // +}; +use core::{ + marker::PhantomData , + ptr::NonNull ,// }; -use core::{marker::PhantomData , ptr::NonNull };/// A wrapper around a blk-mq [`struct request`]. This represents an IO request. ///
rust/kernel/block/mq/tag_set.rs +19 -5
@@ -8,13 +8,27 @@use crate ::{ bindings, - block::mq::{operations::OperationsVTable , request::RequestDataWrapper ,Operations }, - error::{self,Result }, + block::mq::{ + operations::OperationsVTable , + request::RequestDataWrapper , +Operations ,// + }, + error::{ + self, +Result ,// + }, prelude::try_pin_init, - types::Opaque , + types::Opaque ,// +}; +use core::{ + convert::TryInto , + marker::PhantomData ,// +}; +use pin_init::{ + pin_data, + pinned_drop, +PinInit ,// }; -use core::{convert::TryInto , marker::PhantomData }; -use pin_init::{pin_data, pinned_drop,PinInit };/// A wrapper for the C `struct blk_mq_tag_set`. ///
Signature · 1 line
2.43.0
PATCH v3 5/7 rust: block: mq: remove redundant imports and format
In reply to Alvin SunDrop Result, Pin, pin_data, pinned_drop, PinInit, and try_pin_init imports already provided by kernel::prelude.
Simplify error imports and flatten parameters formatting.
--- rust/kernel/block/mq/gen_disk.rs | 7 +++---- rust/kernel/block/mq/operations.rs | 5 +---- rust/kernel/block/mq/request.rs | 2 +- rust/kernel/block/mq/tag_set.rs | 22 ++++------------------ 4 files changed, 9 insertions(+), 27 deletions(-)
rust/kernel/block/mq/gen_disk.rs +3 -4
@@ -12,9 +12,8 @@ TagSet, // }, error::{ - self, from_err_ptr, - Result, // + to_result, // }, fmt::{ self,
@@ -67,7 +66,7 @@ pub fn rotational(mut self, rotational: bool) -> Self {/// and that it is a power of two. pub fn validate_block_size (size:u32 ) ->Result {if !(512 ..=bindings::PAGE_SIZE as u32 ).contains (&size) || !size.is_power_of_two () { -Err (error::code::EINVAL ) +Err (EINVAL ) }else {Ok (()) }
@@ -177,7 +176,7 @@ pub fn build<T: Operations>(// operation, so we will not race. unsafe { bindings::set_capacity (gendisk, self.capacity_sectors) }; -crate ::error::to_result ( +to_result (// SAFETY: `gendisk` points to a valid and initialized instance of // `struct gendisk`. unsafe {
rust/kernel/block/mq/operations.rs +1 -4
@@ -10,10 +10,7 @@ request::RequestDataWrapper, Request, // }, - error::{ - from_result, - Result, // - }, + error::from_result, prelude::*, sync::{ aref::ARef,
rust/kernel/block/mq/request.rs +1 -1
@@ -7,7 +7,7 @@use crate ::{ bindings, block::mq::Operations , - error::Result , + prelude::*, sync::{ aref::{ARef ,
rust/kernel/block/mq/tag_set.rs +4 -18
@@ -4,8 +4,6 @@//! //! C header: [`include/linux/blk-mq.h`](srctree/include/linux/blk-mq.h) -use core::pin::Pin ; -use crate ::{ bindings, block::mq::{
@@ -13,22 +11,14 @@ request::RequestDataWrapper, Operations, // }, - error::{ - self, - Result, // - }, - prelude::try_pin_init, + error::to_result, + prelude::*, types::Opaque, // };use core::{ convert::TryInto , marker::PhantomData ,// }; -use pin_init::{ - pin_data, - pinned_drop, -PinInit ,// -};/// A wrapper for the C `struct blk_mq_tag_set`. ///
@@ -47,11 +37,7 @@ pub struct TagSet<T: Operations> {impl <T :Operations >TagSet <T > {/// Try to create a new tag set -pub fn new ( - nr_hw_queues:u32 , - num_tags:u32 , - num_maps:u32 , - ) ->impl PinInit <Self , error::Error > { +pub fn new (nr_hw_queues:u32 , num_tags:u32 , num_maps:u32 ) ->impl PinInit <Self ,Error > {let tag_set: bindings::blk_mq_tag_set = pin_init::zeroed ();let tag_set:Result <_ > = core::mem::size_of ::<RequestDataWrapper >() .try_into ()
@@ -77,7 +63,7 @@ pub fn new(// SAFETY: we do not move out of `tag_set`. let tag_set: &mut Opaque <_ > =unsafe {Pin ::get_unchecked_mut (tag_set) };// SAFETY: `tag_set` is a reference to an initialized `blk_mq_tag_set`. - error::to_result (unsafe { bindings::blk_mq_alloc_tag_set (tag_set.get ())}) +to_result (unsafe { bindings::blk_mq_alloc_tag_set (tag_set.get ())}) }), _p: PhantomData, })
Signature · 1 line
2.43.0
PATCH v3 6/7 rust: block: rnull: use vertical import style
In reply to Alvin SunConvert use imports to vertical layout for better readability and maintainability.
--- drivers/block/rnull/configfs.rs | 27 +++++++++++++++++++++------ drivers/block/rnull/rnull.rs | 15 +++++++++++---- 2 files changed, 32 insertions(+), 10 deletions(-)
drivers/block/rnull/configfs.rs +21 -6
@@ -1,16 +1,31 @@// SPDX-License-Identifier: GPL-2.0 -use super ::{NullBlkDevice ,THIS_MODULE }; +use super ::{ +NullBlkDevice , +THIS_MODULE ,// +};use kernel::{ - block::mq::gen_disk::{GenDisk ,GenDiskBuilder }, - configfs::{self,AttributeOperations }, + block::mq::gen_disk::{ +GenDisk , +GenDiskBuilder ,// + }, + configfs::{ + self, +AttributeOperations ,// + }, configfs_attrs, - fmt::{self,Write as _}, + fmt::{ + self, +Write as _,// + }, new_mutex, page::PAGE_SIZE , prelude::*, - str::{kstrtobool_bytes,CString }, - sync::Mutex , + str::{ + kstrtobool_bytes, +CString ,// + }, + sync::Mutex ,// };pub (crate )fn subsystem () ->impl PinInit <kernel::configfs::Subsystem <Config >,Error > {
drivers/block/rnull/rnull.rs +11 -4
@@ -10,12 +10,19 @@ self, mq::{ self, - gen_disk::{self, GenDisk}, - Operations, TagSet, - }, + gen_disk::{ + self, + GenDisk, // + }, + Operations, + TagSet, // + }, // }, prelude::*, - sync::{aref::ARef, Arc}, + sync::{ + aref::ARef, + Arc, // + }, // }; module! {
Signature · 1 line
2.43.0
Re: [PATCH v3 6/7] rust: block: rnull: use vertical import style
Quoted 4 lines · Alvin Sun
Convert
useimports to vertical layout for better readability and maintainability.Signed-off-by Alvin Sun <[email protected]>
Best regards,
Andreas Hindborg
PATCH v3 7/7 rust: doctest: use vertical import style
In reply to Alvin SunConvert use imports to vertical layout for better readability and maintainability.
--- scripts/rustdoc_test_gen.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
scripts/rustdoc_test_gen.rs +9 -2
@@ -31,8 +31,15 @@use std::{ fs, fs::File , - io::{BufWriter ,Read ,Write }, - path::{Path ,PathBuf }, + io::{ +BufWriter , +Read , +Write ,// + }, + path::{ +Path , +PathBuf ,// + },// };/// Find the real path to the original file based on the `file` portion of the test name.
Signature · 1 line
2.43.0
Re: [PATCH v3 7/7] rust: doctest: use vertical import style
Quoted 5 lines · Alvin Sun
Convert
useimports to vertical layout for better readability and maintainability.Signed-off-by Alvin Sun <[email protected]>
Please check the titles used by previous commits for files, e.g. "scripts: rust: " would probably be the prefix here. (No need to resend just for this, maintainers may fix it on the fly).
The patch looks OK otherwise of course, thanks!
Cheers,
Miguel
Re: [PATCH v3 7/7] rust: doctest: use vertical import style
In reply to Alvin SunLe 21/05/2026 à 2:57 PM, Alvin Sun a écrit :
Quoted 5 lines
Convert
useimports to vertical layout for better readability and maintainability.Signed-off-by Alvin Sun <[email protected]>---
Assuming this'll go in via the Rust tree, given there are other changers to the rustdoc work which will likely go in that way. (But, if we'd prefer it to go in via kselftest/kunit, that shouldn't be a problem.)
Cheers,
-- David
Quoted 26 lines
scripts/rustdoc_test_gen.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)scripts/rustdoc_test_gen.rs +9
-2@@ -31,8 +31,15 @@use std::{ fs, fs::File , - io::{BufWriter ,Read ,Write }, - path::{Path ,PathBuf }, + io::{ +BufWriter , +Read , +Write ,// + }, + path::{ +Path , +PathBuf ,// + },// };/// Find the real path to the original file based on the `file` portion of the test name.
Quoted 3 lines · Alvin Sun
Adopt the vertical import style and drop redundant imports already re-exported via
kernel::prelude.
I can take this if block and misc Ack. The changes are straightforward anyway.
Thanks!
Cheers,
Miguel
Quoted 4 lines · Miguel Ojeda
Quoted 2 lines · Alvin Sun
Adopt the vertical import style and drop redundant imports already re-exported via
kernel::prelude.I can take this if block and misc Ack. The changes are straightforward anyway.
Hi Miguel,
I would like to follow up on the remaining patches from this series:
rust: block: mq: use vertical import style
rust: block: mq: remove redundant imports and format
rust: block: rnull: use vertical import style
rust: doctest: use vertical import style
As far as I can tell, these have not been merged yet. Andreas already acked the block parts [1][2][3] and David Gow acked the doctest change [4]. Is there anything else needed from my side before they can be picked up, such as a rebase onto a newer base?
[1] https://lore.kernel.org/rust-for-linux/[email protected]/
[2] https://lore.kernel.org/rust-for-linux/[email protected]/
[3] https://lore.kernel.org/rust-for-linux/[email protected]/
[4] https://lore.kernel.org/rust-for-linux/[email protected]/
Best regards,
Alvin
Quoted 5 lines
Thanks!
Cheers,
Miguel
Hi Miguel and Andreas,
I would like to follow up on the remaining patches from the "rust: use vertical import style and remove redundant imports" series:
rust: block: mq: use vertical import style
rust: block: mq: remove redundant imports and format
rust: block: rnull: use vertical import style
rust: doctest: use vertical import style
As far as I can tell, these have not been merged yet. Andreas already acked the block parts [1][2][3] and David Gow acked the doctest change [4]. Is there anything else needed from my side before they can be picked up, such as a rebase onto a newer base?
[1] https://lore.kernel.org/rust-for-linux/[email protected]/
[2] https://lore.kernel.org/rust-for-linux/[email protected]/
[3] https://lore.kernel.org/rust-for-linux/[email protected]/
[4] https://lore.kernel.org/rust-for-linux/[email protected]/
Thanks,
Alvin
Apologies — this earlier message was sent by accident while I was editing. Please disregard it.
Best regards,
Alvin
Quoted 23 lines · Alvin Sun
Hi Miguel and Andreas,
I would like to follow up on the remaining patches from the "rust: use vertical import style and remove redundant imports" series:
rust: block: mq: use vertical import style
rust: block: mq: remove redundant imports and format
rust: block: rnull: use vertical import style
rust: doctest: use vertical import styleAs far as I can tell, these have not been merged yet. Andreas already acked the block parts [1][2][3] and David Gow acked the doctest change [4]. Is there anything else needed from my side before they can be picked up, such as a rebase onto a newer base?
[1] https://lore.kernel.org/rust-for-linux/[email protected]/
[2] https://lore.kernel.org/rust-for-linux/[email protected]/
[3] https://lore.kernel.org/rust-for-linux/[email protected]/
[4] https://lore.kernel.org/rust-for-linux/[email protected]/Thanks,
Alvin
Quoted 5 lines · Alvin Sun
rust: block: mq: use vertical import style
rust: block: mq: remove redundant imports and format
rust: block: rnull: use vertical import style
rust: doctest: use vertical import style
For the block ones, Jens may be picking them; but if block/Jens/Andreas prefer, I am happy to do so too of course.
For the doctest script one, I will pick it up right away.
Cheers,
Miguel
Quoted 9 lines · Miguel Ojeda
Quoted 4 lines · Alvin Sun
rust: block: mq: use vertical import style
rust: block: mq: remove redundant imports and format
rust: block: rnull: use vertical import style
rust: doctest: use vertical import styleFor the block ones, Jens may be picking them; but if
block/Jens/Andreasprefer, I am happy to do so too of course.For the doctest script one, I will pick it up right away.
Thanks!
Best regards,
Alvin
Quoted 3 lines
Cheers,
Miguel
Andreas Hindborg
maintainerQuoted 9 lines · Miguel Ojeda
Quoted 5 lines · Alvin Sun
rust: block: mq: use vertical import style
rust: block: mq: remove redundant imports and format
rust: block: rnull: use vertical import style
rust: doctest: use vertical import styleFor the block ones, Jens may be picking them; but if
block/Jens/Andreasprefer, I am happy to do so too of course.
I believe Jens will take these.
Best regards,
Andreas Hindborg
Quoted 2 lines · Alvin Sun
rust: doctest: use vertical import style
Applied (this one only) to rust-next -- thanks everyone!
Cheers,
Miguel