[PATCH v4 1/2] rust: scatterlist: return u32 from SGEntry::dma_len()
From: Lorenzo Delgado
Date: Sun Sep 27 2026 - 14:13:32 EST
`SGEntry::dma_len()` returns `ResourceSize`, but the length of a DMA
segment is not the size of a resource. The C side stores it as an
`unsigned int` (`dma_length` in `struct scatterlist`), the helper
returns `unsigned int`, and a single segment is bounded by the
device's `max_segment_size`, which is an `unsigned int` as well. The
method only widens the value to `resource_size_t`.
Return `u32`, which is what the binding already produces, and drop the
`.into()` along with its `clippy::useless_conversion` allow.
tyr widens the length to `u64`, which is now a real conversion on
every architecture, so drop its `useless_conversion` allow too.
nova-core converts it to `usize` through `FromSafeCast`, which already
covers `u32`, so it needs no change.
Suggested-by: Danilo Krummrich <dakr@xxxxxxxxxx>
Link: https://lore.kernel.org/r/DLNPXJ4WPH4L.2MBUGV1TAESYY@xxxxxxxxxx
Signed-off-by: Lorenzo Delgado <lnsdev@xxxxxxxxx>
---
drivers/gpu/drm/tyr/vm.rs | 1 -
rust/kernel/scatterlist.rs | 9 +++------
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/tyr/vm.rs b/drivers/gpu/drm/tyr/vm.rs
index c5e307b1e241..1dd11b2b1253 100644
--- a/drivers/gpu/drm/tyr/vm.rs
+++ b/drivers/gpu/drm/tyr/vm.rs
@@ -644,7 +644,6 @@ fn sm_step_map<'op>(
// Expressly convert to u64 to work with arm 32-bit builds.
#[allow(clippy::useless_conversion)]
let mut paddr = u64::from(sgt_entry.dma_address());
- #[allow(clippy::useless_conversion)]
let mut sgt_entry_length = u64::from(sgt_entry.dma_len());
if bytes_left_to_map == 0 {
diff --git a/rust/kernel/scatterlist.rs b/rust/kernel/scatterlist.rs
index b83c468b5c63..f37bf29fdbca 100644
--- a/rust/kernel/scatterlist.rs
+++ b/rust/kernel/scatterlist.rs
@@ -34,9 +34,7 @@
bindings,
device::{Bound, Device},
devres::Devres,
- dma, error,
- io::ResourceSize,
- page,
+ dma, error, page,
prelude::*,
sync::aref::ARef,
types::Opaque,
@@ -90,10 +88,9 @@ pub fn dma_address(&self) -> dma::DmaAddress {
/// Returns the length of this SG entry in bytes.
#[inline]
- pub fn dma_len(&self) -> ResourceSize {
- #[allow(clippy::useless_conversion)]
+ pub fn dma_len(&self) -> u32 {
// SAFETY: `self.as_raw()` is a valid pointer to a `struct scatterlist`.
- unsafe { bindings::sg_dma_len(self.as_raw()) }.into()
+ unsafe { bindings::sg_dma_len(self.as_raw()) }
}
}
--
2.55.0