diff options
| author | Bartosz Golaszewski | 2025-09-08 09:16:23 +0200 |
|---|---|---|
| committer | Bartosz Golaszewski | 2025-09-08 09:16:23 +0200 |
| commit | e10a7cf4f69ecdc42ab4a17deaed86d34e8cb035 (patch) | |
| tree | c4096642b7c9bc653e26bf6a05d8c68f2d14e0c4 /rust/kernel/alloc/allocator_test.rs | |
| parent | 79d15f23f232f90bfd8823239fd57b964d053548 (diff) | |
| parent | 76eeb9b8de9880ca38696b2fb56ac45ac0a25c6c (diff) | |
Merge tag 'v6.17-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux into gpio/for-next
Linux 6.17-rc5
Diffstat (limited to 'rust/kernel/alloc/allocator_test.rs')
| -rw-r--r-- | rust/kernel/alloc/allocator_test.rs | 11 |
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; |
