rust: block: mq: remove redundant imports and format

Drop `Result`, `Pin`, `pin_data`, `pinned_drop`, `PinInit`, and
`try_pin_init` imports already provided by `kernel::prelude`.

Simplify `error` imports and flatten parameters formatting.

Reviewed-by: Onur Özkan <work@onurozkan.dev>
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
Acked-by: Andreas Hindborg <a.hindborg@kernel.org>
Link: https://msgid.link/20260521-miscdev-use-format-v3-5-56240ca70d0c@linux.dev
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
Link: https://patch.msgid.link/20260929-rust-block-for-v7-4-rc1-b4-v1-2-642a4c1aebd7@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Alvin Sun 2026-09-29 11:34:00 +02:00 committed by Jens Axboe
parent 020185c5f4
commit 06e75dbe89
4 changed files with 9 additions and 27 deletions

View File

@ -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(())
}
@ -190,7 +189,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 {

View File

@ -10,10 +10,7 @@
request::RequestDataWrapper,
Request, //
},
error::{
from_result,
Result, //
},
error::from_result,
prelude::*,
sync::{
aref::ARef,

View File

@ -7,7 +7,7 @@
use crate::{
bindings,
block::mq::Operations,
error::Result,
prelude::*,
sync::{
aref::{
ARef,

View File

@ -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,
})