[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251008124619.3160-2-work@onurozkan.dev>
Date: Wed, 8 Oct 2025 15:46:16 +0300
From: Onur Özkan <work@...rozkan.dev>
To: rust-for-linux@...r.kernel.org
Cc: ojeda@...nel.org,
alex.gaynor@...il.com,
boqun.feng@...il.com,
gary@...yguo.net,
bjorn3_gh@...tonmail.com,
lossin@...nel.org,
aliceryhl@...gle.com,
tmgross@...ch.edu,
dakr@...nel.org,
linux-kernel@...r.kernel.org,
acourbot@...dia.com,
airlied@...il.com,
simona@...ll.ch,
maarten.lankhorst@...ux.intel.com,
mripard@...nel.org,
tzimmermann@...e.de,
corbet@....net,
lyude@...hat.com,
linux-doc@...r.kernel.org,
linux-mm@...ck.org,
Onur Özkan <work@...rozkan.dev>
Subject: [PATCH v2 1/4] rust: xarray: move pointer check into `XArray::new`
There will be multiple functions that will store into XArray.
It's not ideal to duplicate this check in all of them. Moving it
into the constructor function will remove the need for duplication.
Signed-off-by: Onur Özkan <work@...rozkan.dev>
---
rust/kernel/xarray.rs | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
index a49d6db28845..90e27cd5197e 100644
--- a/rust/kernel/xarray.rs
+++ b/rust/kernel/xarray.rs
@@ -87,6 +87,12 @@ pub enum AllocKind {
impl<T: ForeignOwnable> XArray<T> {
/// Creates a new initializer for this type.
pub fn new(kind: AllocKind) -> impl PinInit<Self> {
+ // Ensure pointers stored in XArray are suitably aligned.
+ build_assert!(
+ T::FOREIGN_ALIGN >= 4,
+ "pointers stored in XArray must be 4-byte aligned"
+ );
+
let flags = match kind {
AllocKind::Alloc => bindings::XA_FLAGS_ALLOC,
AllocKind::Alloc1 => bindings::XA_FLAGS_ALLOC1,
@@ -230,10 +236,6 @@ pub fn store(
value: T,
gfp: alloc::Flags,
) -> Result<Option<T>, StoreError<T>> {
- build_assert!(
- T::FOREIGN_ALIGN >= 4,
- "pointers stored in XArray must be 4-byte aligned"
- );
let new = value.into_foreign();
let old = {
--
2.51.0
Powered by blists - more mailing lists