[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250713-xarray-insert-reserve-v2-2-b939645808a2@gmail.com>
Date: Sun, 13 Jul 2025 08:05:48 -0400
From: Tamir Duberstein <tamird@...il.com>
To: Andreas Hindborg <a.hindborg@...nel.org>,
Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>,
Matthew Wilcox <willy@...radead.org>,
Andrew Morton <akpm@...ux-foundation.org>
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-mm@...ck.org,
Daniel Almeida <daniel.almeida@...labora.com>,
Tamir Duberstein <tamird@...il.com>, Janne Grunau <j@...nau.net>
Subject: [PATCH v2 2/3] rust: xarray: implement Default for AllocKind
Most users are likely to want 0-indexed arrays. Clean up the
documentation test accordingly.
Tested-by: Janne Grunau <j@...nau.net>
Reviewed-by: Janne Grunau <j@...nau.net>
Signed-off-by: Tamir Duberstein <tamird@...il.com>
---
rust/kernel/xarray.rs | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
index b9f4f2cd8d6a..101f61c0362d 100644
--- a/rust/kernel/xarray.rs
+++ b/rust/kernel/xarray.rs
@@ -24,10 +24,11 @@
/// # Examples
///
/// ```rust
-/// use kernel::alloc::KBox;
-/// use kernel::xarray::{AllocKind, XArray};
+/// # use kernel::alloc::KBox;
+/// # use kernel::xarray::XArray;
+/// # use pin_init::stack_pin_init;
///
-/// let xa = KBox::pin_init(XArray::new(AllocKind::Alloc1), GFP_KERNEL)?;
+/// stack_pin_init!(let xa = XArray::new(Default::default()));
///
/// let dead = KBox::new(0xdead, GFP_KERNEL)?;
/// let beef = KBox::new(0xbeef, GFP_KERNEL)?;
@@ -75,8 +76,10 @@ fn drop(self: Pin<&mut Self>) {
}
/// Flags passed to [`XArray::new`] to configure the array's allocation tracking behavior.
+#[derive(Default)]
pub enum AllocKind {
/// Consider the first element to be at index 0.
+ #[default]
Alloc,
/// Consider the first element to be at index 1.
Alloc1,
--
2.50.1
Powered by blists - more mailing lists