summaryrefslogtreecommitdiff
path: root/rust/kernel/alloc/allocator_test.rs
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2025-08-23 06:45:22 +1000
committerDave Airlie <airlied@redhat.com>2025-08-23 06:45:53 +1000
commitf9915c391cf72789ec5b6d5966ba82c2bca5daa7 (patch)
tree42f9e1d38a2c1c340dd9fcf3207a6f404ae1963a /rust/kernel/alloc/allocator_test.rs
parentdbb2c3adc4a641d9f136005285bcbba15227249c (diff)
parent1a2cf179e2973f6801c67397ecc987391b084bcf (diff)
Merge tag 'drm-misc-fixes-2025-08-21' of https://gitlab.freedesktop.org/drm/misc/kernel into drm-fixes
A bunch of fixes for 6.17: - analogix_dp: devm_drm_bridge_alloc() error handling fix - gaudi: Memory deallocation fix - gpuvm: Documentation warning fix - hibmc: Various misc fixes - nouveau: Memory leak fixes, typos - panic: u64 division handling on 32 bits architecture fix - rockchip: Kconfig fix, register caching fix - rust: memory layout and safety fixes - tests: Endianness fixes Signed-off-by: Dave Airlie <airlied@redhat.com> From: Maxime Ripard <mripard@redhat.com> Link: https://lore.kernel.org/r/20250821-economic-dandelion-rooster-c57fa9@houat
Diffstat (limited to 'rust/kernel/alloc/allocator_test.rs')
-rw-r--r--rust/kernel/alloc/allocator_test.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/rust/kernel/alloc/allocator_test.rs b/rust/kernel/alloc/allocator_test.rs
index a3074480bd8d..90dd987d40e4 100644
--- a/rust/kernel/alloc/allocator_test.rs
+++ b/rust/kernel/alloc/allocator_test.rs
@@ -22,6 +22,17 @@ pub type Kmalloc = Cmalloc;
pub type Vmalloc = Kmalloc;
pub type KVmalloc = Kmalloc;
+impl Cmalloc {
+ /// Returns a [`Layout`] that makes [`Kmalloc`] fulfill the requested size and alignment of
+ /// `layout`.
+ pub fn aligned_layout(layout: Layout) -> Layout {
+ // Note that `layout.size()` (after padding) is guaranteed to be a multiple of
+ // `layout.align()` which together with the slab guarantees means that `Kmalloc` will return
+ // a properly aligned object (see comments in `kmalloc()` for more information).
+ layout.pad_to_align()
+ }
+}
+
extern "C" {
#[link_name = "aligned_alloc"]
fn libc_aligned_alloc(align: usize, size: usize) -> *mut crate::ffi::c_void;