Skip to content

Commit 9b25d41

Browse files
author
Danilo Krummrich
committed
rust: alloc: cleanup imports and use "kernel vertical" style
Change all imports in the alloc module to use the "kernel vertical" import style [1]. While at it, drop unnecessary imports covered by prelude::*. Link: https://docs.kernel.org/rust/coding-guidelines.html#imports [1] Reviewed-by: Eliot Courtney <ecourtney@nvidia.com> Link: https://patch.msgid.link/20260513190946.619810-1-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
1 parent f497aae commit 9b25d41

7 files changed

Lines changed: 116 additions & 46 deletions

File tree

‎rust/kernel/alloc.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ pub use self::kvec::Vec;
2222
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
2323
pub struct AllocError;
2424

25-
use crate::error::{code::EINVAL, Result};
26-
use core::{alloc::Layout, ptr::NonNull};
25+
use crate::prelude::*;
26+
27+
use core::{
28+
alloc::Layout,
29+
ptr::NonNull, //
30+
};
2731

2832
/// Flags to be used when allocating memory.
2933
///

‎rust/kernel/alloc/allocator.rs‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,25 @@
88
//!
99
//! Reference: <https://docs.kernel.org/core-api/memory-allocation.html>
1010
11-
use super::Flags;
12-
use core::alloc::Layout;
13-
use core::ptr;
14-
use core::ptr::NonNull;
15-
16-
use crate::alloc::{AllocError, Allocator, NumaNode};
17-
use crate::bindings;
18-
use crate::page;
11+
use super::{
12+
AllocError,
13+
Allocator,
14+
Flags,
15+
NumaNode, //
16+
};
17+
18+
use crate::{
19+
bindings,
20+
page, //
21+
};
22+
23+
use core::{
24+
alloc::Layout,
25+
ptr::{
26+
self,
27+
NonNull, //
28+
}, //
29+
};
1930

2031
const ARCH_KMALLOC_MINALIGN: usize = bindings::ARCH_KMALLOC_MINALIGN;
2132

‎rust/kernel/alloc/allocator/iter.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// SPDX-License-Identifier: GPL-2.0
22

33
use super::Vmalloc;
4+
45
use crate::page;
5-
use core::marker::PhantomData;
6-
use core::ptr::NonNull;
6+
7+
use core::{
8+
marker::PhantomData,
9+
ptr::NonNull, //
10+
};
711

812
/// An [`Iterator`] of [`page::BorrowedPage`] items owned by a [`Vmalloc`] allocation.
913
///

‎rust/kernel/alloc/kbox.rs‎

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,47 @@
33
//! Implementation of [`Box`].
44
55
#[allow(unused_imports)] // Used in doc comments.
6-
use super::allocator::{KVmalloc, Kmalloc, Vmalloc, VmallocPageIter};
7-
use super::{AllocError, Allocator, Flags, NumaNode};
8-
use core::alloc::Layout;
9-
use core::borrow::{Borrow, BorrowMut};
10-
use core::marker::PhantomData;
11-
use core::mem::ManuallyDrop;
12-
use core::mem::MaybeUninit;
13-
use core::ops::{Deref, DerefMut};
14-
use core::pin::Pin;
15-
use core::ptr::NonNull;
16-
use core::result::Result;
17-
18-
use crate::ffi::c_void;
19-
use crate::fmt;
20-
use crate::init::InPlaceInit;
21-
use crate::page::AsPageIter;
22-
use crate::types::ForeignOwnable;
23-
use pin_init::{InPlaceWrite, Init, PinInit, ZeroableOption};
6+
use super::allocator::{
7+
KVmalloc,
8+
Kmalloc,
9+
Vmalloc,
10+
VmallocPageIter, //
11+
};
12+
13+
use super::{
14+
AllocError,
15+
Allocator,
16+
Flags,
17+
NumaNode, //
18+
};
19+
20+
use crate::{
21+
fmt,
22+
page::AsPageIter,
23+
prelude::*,
24+
types::ForeignOwnable, //
25+
};
26+
27+
use core::{
28+
alloc::Layout,
29+
borrow::{
30+
Borrow,
31+
BorrowMut, //
32+
},
33+
marker::PhantomData,
34+
mem::{
35+
ManuallyDrop,
36+
MaybeUninit, //
37+
},
38+
ops::{
39+
Deref,
40+
DerefMut, //
41+
},
42+
ptr::NonNull,
43+
result::Result, //
44+
};
45+
46+
use pin_init::ZeroableOption;
2447

2548
/// The kernel's [`Box`] type -- a heap allocation for a single value of type `T`.
2649
///

‎rust/kernel/alloc/kvec.rs‎

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,52 @@
33
//! Implementation of [`Vec`].
44
55
use super::{
6-
allocator::{KVmalloc, Kmalloc, Vmalloc, VmallocPageIter},
6+
allocator::{
7+
KVmalloc,
8+
Kmalloc,
9+
Vmalloc,
10+
VmallocPageIter, //
11+
},
712
layout::ArrayLayout,
8-
AllocError, Allocator, Box, Flags, NumaNode,
13+
AllocError,
14+
Allocator,
15+
Box,
16+
Flags,
17+
NumaNode, //
918
};
19+
1020
use crate::{
1121
fmt,
1222
page::{
1323
AsPageIter,
1424
PAGE_SIZE, //
15-
},
25+
}, //
1626
};
27+
1728
use core::{
18-
borrow::{Borrow, BorrowMut},
29+
borrow::{
30+
Borrow,
31+
BorrowMut, //
32+
},
1933
marker::PhantomData,
20-
mem::{ManuallyDrop, MaybeUninit},
21-
ops::Deref,
22-
ops::DerefMut,
23-
ops::Index,
24-
ops::IndexMut,
25-
ptr,
26-
ptr::NonNull,
27-
slice,
28-
slice::SliceIndex,
34+
mem::{
35+
ManuallyDrop,
36+
MaybeUninit, //
37+
},
38+
ops::{
39+
Deref,
40+
DerefMut,
41+
Index,
42+
IndexMut, //
43+
},
44+
ptr::{
45+
self,
46+
NonNull, //
47+
},
48+
slice::{
49+
self,
50+
SliceIndex, //
51+
}, //
2952
};
3053

3154
mod errors;

‎rust/kernel/alloc/kvec/errors.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
//! Errors for the [`Vec`] type.
44
5-
use kernel::fmt;
6-
use kernel::prelude::*;
5+
use crate::{
6+
fmt,
7+
prelude::*, //
8+
};
79

810
/// Error type for [`Vec::push_within_capacity`].
911
pub struct PushError<T>(pub T);

‎rust/kernel/alloc/layout.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
//!
55
//! Custom layout types extending or improving [`Layout`].
66
7-
use core::{alloc::Layout, marker::PhantomData};
7+
use core::{
8+
alloc::Layout,
9+
marker::PhantomData, //
10+
};
811

912
/// Error when constructing an [`ArrayLayout`].
1013
pub struct LayoutError;

0 commit comments

Comments
 (0)