lkml.org 
[lkml]   [2026]   [May]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
Subject[PATCH RFC 4/6] rust/scatterlist: add SGEntry::init_one
Add a method to allow creation of an SGEntry with borrowed data.
Analogous of `sg_init_one` in C.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
---
rust/kernel/scatterlist.rs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/rust/kernel/scatterlist.rs b/rust/kernel/scatterlist.rs
index 146e738cbd4351b41c11dd39a45e20f404c5cd64..b065762af1a734fcdd5d3acde89199f1a626fd89 100644
--- a/rust/kernel/scatterlist.rs
+++ b/rust/kernel/scatterlist.rs
@@ -95,6 +95,24 @@ pub fn dma_len(&self) -> ResourceSize {
// SAFETY: `self.as_raw()` is a valid pointer to a `struct scatterlist`.
unsafe { bindings::sg_dma_len(self.as_raw()) }.into()
}
+
+ /// Initialize a new entry with borrowed data.
+ ///
+ /// # Safety
+ ///
+ /// Callers must ensure that:
+ /// - `buf` is a valid pointer
+ /// - `buf_len` describes a valid allocation size for this pointer
+ pub unsafe fn init_one(
+ val: &'_ mut core::mem::MaybeUninit<bindings::scatterlist>,
+ buf: NonNull<u8>,
+ buf_len: u32,
+ ) -> &'_ Self {
+ // SAFETY: `val` points to a correctly sized `struct scatterlist`.
+ unsafe { bindings::sg_init_one(val.as_mut_ptr(), buf.as_ptr().cast(), buf_len) };
+ // SAFETY: `val` points to an initialized `struct scatterlist`.
+ unsafe { Self::from_raw(val.as_mut_ptr()) }
+ }
}

/// The borrowed generic type of an [`SGTable`], representing a borrowed or externally managed
--
2.47.3


\
 
 \ /
  Last update: 2026-05-05 10:15    [W:0.088 / U:21.210 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and my Meterkast|Read the blog