Skip to contentSkip to conversation

rust: alloc: cleanup imports and use "kernel vertical" style

PATCH Applied Danilo Krummrich 1 participant 3 messages May 13 – May 20

Subsystems (2)
lore
Share & tools
lore

Danilo Krummrich

author maintainer
#0 lore raw

PATCH v2 1/2 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::*.

---
Changes in v2:
- Adjust rust/kernel/alloc.rs as well.
- Don't change scope of allow(unused_imports) in kbox.rs.

---
 rust/kernel/alloc.rs                |  8 +++-
 rust/kernel/alloc/allocator.rs      | 27 +++++++++----
 rust/kernel/alloc/allocator/iter.rs |  8 +++-
 rust/kernel/alloc/kbox.rs           | 59 ++++++++++++++++++++---------
 rust/kernel/alloc/kvec.rs           | 49 +++++++++++++++++-------
 rust/kernel/alloc/kvec/errors.rs    |  6 ++-
 rust/kernel/alloc/layout.rs         |  5 ++-
 7 files changed, 116 insertions(+), 46 deletions(-)
rust/kernel/alloc.rs +6 -2
index e38720349dcf..21067bde6860 100644
@@ -22,8 +22,12 @@
 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
 pub struct AllocError;
 
-use crate::error::{code::EINVAL, Result};
-use core::{alloc::Layout, ptr::NonNull};
+use crate::prelude::*;
+
+use core::{
+    alloc::Layout,
+    ptr::NonNull, //
+};
 
 /// Flags to be used when allocating memory.
 ///
rust/kernel/alloc/allocator.rs +19 -8
index 63bfb91b3671..af20332d59f7 100644
@@ -8,14 +8,25 @@
 //!
 //! Reference: <https://docs.kernel.org/core-api/memory-allocation.html>
 
-use super::Flags;
-use core::alloc::Layout;
-use core::ptr;
-use core::ptr::NonNull;
-
-use crate::alloc::{AllocError, Allocator, NumaNode};
-use crate::bindings;
-use crate::page;
+use super::{
+    AllocError,
+    Allocator,
+    Flags,
+    NumaNode, //
+};
+
+use crate::{
+    bindings,
+    page, //
+};
+
+use core::{
+    alloc::Layout,
+    ptr::{
+        self,
+        NonNull, //
+    }, //
+};
 
 const ARCH_KMALLOC_MINALIGN: usize = bindings::ARCH_KMALLOC_MINALIGN;
 
rust/kernel/alloc/allocator/iter.rs +6 -2
index e0a70b7a744a..02fda3ea5cae 100644
@@ -1,9 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0
 
 use super::Vmalloc;
+
 use crate::page;
-use core::marker::PhantomData;
-use core::ptr::NonNull;
+
+use core::{
+    marker::PhantomData,
+    ptr::NonNull, //
+};
 
 /// An [`Iterator`] of [`page::BorrowedPage`] items owned by a [`Vmalloc`] allocation.
 ///
rust/kernel/alloc/kbox.rs +41 -18

65 lines not on this page · raw message

rust/kernel/alloc/kvec.rs +36 -13

65 lines not on this page · raw message

rust/kernel/alloc/kvec/errors.rs +4 -2
index 985c5f2c3962..aaca6446516a 100644
@@ -2,8 +2,10 @@
 
 //! Errors for the [`Vec`] type.
 
-use kernel::fmt;
-use kernel::prelude::*;
+use crate::{
+    fmt,
+    prelude::*, //
+};
 
 /// Error type for [`Vec::push_within_capacity`].
 pub struct PushError<T>(pub T);
rust/kernel/alloc/layout.rs +4 -1
index 9f8be72feb7a..b629da4aed07 100644
@@ -4,7 +4,10 @@
 //!
 //! Custom layout types extending or improving [`Layout`].
 
-use core::{alloc::Layout, marker::PhantomData};
+use core::{
+    alloc::Layout,
+    marker::PhantomData, //
+};
 
 /// Error when constructing an [`ArrayLayout`].
 pub struct LayoutError;

base-commit: f497aae6ded43f91b1dbf29a35d7062823635640

Signature · 1 line
2.54.0
author maintainer
#1 lore raw

PATCH v2 2/2 rust: alloc: cleanup doctest imports to "kernel vertical" style

Change all imports in the alloc module's doctests to use the "kernel vertical" import style [1].

While at it, drop imports that are automatically included in doctests.

---
 rust/kernel/alloc/allocator.rs |  7 +++++--
 rust/kernel/alloc/kbox.rs      | 17 +++++++++++------
 rust/kernel/alloc/kvec.rs      | 10 +++++++---
 rust/kernel/alloc/layout.rs    |  5 ++++-
 4 files changed, 27 insertions(+), 12 deletions(-)
rust/kernel/alloc/allocator.rs +5 -2
index af20332d59f7..562e41925ada 100644
@@ -174,8 +174,11 @@ impl Vmalloc {
     /// # Examples
     ///
     /// ```
-    /// # use core::ptr::{NonNull, from_mut};
-    /// # use kernel::{page, prelude::*};
+    /// # use core::ptr::{
+    /// #     from_mut,
+    /// #     NonNull, //
+    /// # };
+    /// # use kernel::page;
     /// use kernel::alloc::allocator::Vmalloc;
     ///
     /// let mut vbox = VBox::<[u8; page::PAGE_SIZE]>::new_uninit(GFP_KERNEL)?;
rust/kernel/alloc/kbox.rs +11 -6
index b8097dec3869..31b2588ed5bf 100644
@@ -297,7 +297,10 @@ pub fn pin(x: T, flags: Flags) -> Result<Pin<Box<T, A>>, AllocError>
     /// # Examples
     ///
     /// ```
-    /// use kernel::sync::{new_spinlock, SpinLock};
+    /// use kernel::sync::{
+    ///     new_spinlock,
+    ///     SpinLock, //
+    /// };
     ///
     /// struct Inner {
     ///     a: u32,
@@ -590,7 +593,6 @@ fn deref_mut(&mut self) -> &mut T {
 ///
 /// ```
 /// # use core::borrow::Borrow;
-/// # use kernel::alloc::KBox;
 /// struct Foo<B: Borrow<u32>>(B);
 ///
 /// // Owned instance.
@@ -618,7 +620,6 @@ fn borrow(&self) -> &T {
 ///
 /// ```
 /// # use core::borrow::BorrowMut;
-/// # use kernel::alloc::KBox;
 /// struct Foo<B: BorrowMut<u32>>(B);
 ///
 /// // Owned instance.
@@ -683,9 +684,13 @@ fn drop(&mut self) {
 /// # Examples
 ///
 /// ```
-/// # use kernel::prelude::*;
-/// use kernel::alloc::allocator::VmallocPageIter;
-/// use kernel::page::{AsPageIter, PAGE_SIZE};
+/// use kernel::{
+///     alloc::allocator::VmallocPageIter,
+///     page::{
+///         AsPageIter,
+///         PAGE_SIZE, //
+///     }, //
+/// };
 ///
 /// let mut vbox = VBox::new((), GFP_KERNEL)?;
 ///
rust/kernel/alloc/kvec.rs +7 -3
index ad1839f1375b..6f35484387de 100644
@@ -1187,9 +1187,13 @@ fn into_iter(self) -> Self::IntoIter {
 /// # Examples
 ///
 /// ```
-/// # use kernel::prelude::*;
-/// use kernel::alloc::allocator::VmallocPageIter;
-/// use kernel::page::{AsPageIter, PAGE_SIZE};
+/// use kernel::{
+///     alloc::allocator::VmallocPageIter,
+///     page::{
+///         AsPageIter,
+///         PAGE_SIZE, //
+///     }, //
+/// };
 ///
 /// let mut vec = VVec::<u8>::new();
 ///
rust/kernel/alloc/layout.rs +4 -1
index b629da4aed07..62a459c66baf 100644
@@ -50,7 +50,10 @@ pub const fn empty() -> Self {
     /// # Examples
     ///
     /// ```
-    /// # use kernel::alloc::layout::{ArrayLayout, LayoutError};
+    /// # use kernel::alloc::layout::{
+    /// #     ArrayLayout,
+    /// #     LayoutError, //
+    /// # };
     /// let layout = ArrayLayout::<i32>::new(15)?;
     /// assert_eq!(layout.len(), 15);
     ///
Signature · 1 line
2.54.0
author maintainer Applied
#2 lore raw
In reply to Danilo Krummrich
Quoted 1 line · Danilo Krummrich

[PATCH v2 1/2] rust: alloc: cleanup imports and use "kernel vertical" style

Applied, thanks!

Branch: alloc-next
Tree: [email protected]:Rust-for-Linux/linux.git

[1/2] rust: alloc: cleanup imports and use "kernel vertical" style

      commit: 9b25d4111e91
[2/2] rust: alloc: cleanup doctest imports to "kernel vertical" style
      commit: ec51531fb8ef

The patches will appear in the next linux-next integration (typically within 24 hours on weekdays).

The patches are queued up for the upcoming merge window for the next major kernel release.