diff options
| author | Dave Airlie <airlied@redhat.com> | 2026-03-13 10:39:57 +1000 |
|---|---|---|
| committer | Dave Airlie <airlied@redhat.com> | 2026-03-13 10:40:17 +1000 |
| commit | b28913e897edfeedc4e33b03b28068b27d002e6c (patch) | |
| tree | 37f1b32aed1ddcc88cf6dab0f4e98bed628a3e82 /rust/kernel/ptr.rs | |
| parent | dd0365021be3e8693680bb1d2616edf7d5e17800 (diff) | |
| parent | 0073a17b466684413ac87cf8ff6c19560db44e7a (diff) | |
Merge tag 'drm-rust-fixes-2026-03-12' of https://gitlab.freedesktop.org/drm/rust/kernel into drm-fixes
Core Changes:
- Fix safety issue in dma_read! and dma_write!.
Driver Changes (Nova Core):
- Fix UB in DmaGspMem pointer accessors.
- Fix stack overflow in GSP memory allocation.
Signed-off-by: Dave Airlie <airlied@redhat.com>
From: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/abNBSol3CLRCqlkZ@google.com
Diffstat (limited to 'rust/kernel/ptr.rs')
| -rw-r--r-- | rust/kernel/ptr.rs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/rust/kernel/ptr.rs b/rust/kernel/ptr.rs index 5b6a382637fe..bdc2d79ff669 100644 --- a/rust/kernel/ptr.rs +++ b/rust/kernel/ptr.rs @@ -2,7 +2,13 @@ //! Types and functions to work with pointers and addresses. -use core::mem::align_of; +pub mod projection; +pub use crate::project_pointer as project; + +use core::mem::{ + align_of, + size_of, // +}; use core::num::NonZero; /// Type representing an alignment, which is always a power of two. @@ -225,3 +231,25 @@ macro_rules! impl_alignable_uint { } impl_alignable_uint!(u8, u16, u32, u64, usize); + +/// Trait to represent compile-time known size information. +/// +/// This is a generalization of [`size_of`] that works for dynamically sized types. +pub trait KnownSize { + /// Get the size of an object of this type in bytes, with the metadata of the given pointer. + fn size(p: *const Self) -> usize; +} + +impl<T> KnownSize for T { + #[inline(always)] + fn size(_: *const Self) -> usize { + size_of::<T>() + } +} + +impl<T> KnownSize for [T] { + #[inline(always)] + fn size(p: *const Self) -> usize { + p.len() * size_of::<T>() + } +} |
