2
2
3
3
//! Allocator support.
4
4
5
+ use super :: { flags:: * , Flags } ;
5
6
use core:: alloc:: { GlobalAlloc , Layout } ;
6
7
use core:: ptr;
7
8
@@ -15,7 +16,7 @@ struct KernelAllocator;
15
16
///
16
17
/// - `ptr` can be either null or a pointer which has been allocated by this allocator.
17
18
/// - `new_layout` must have a non-zero size.
18
- unsafe fn krealloc_aligned ( ptr : * mut u8 , new_layout : Layout , flags : bindings :: gfp_t ) -> * mut u8 {
19
+ unsafe fn krealloc_aligned ( ptr : * mut u8 , new_layout : Layout , flags : Flags ) -> * mut u8 {
19
20
// Customized layouts from `Layout::from_size_align()` can have size < align, so pad first.
20
21
let layout = new_layout. pad_to_align ( ) ;
21
22
@@ -36,14 +37,14 @@ unsafe fn krealloc_aligned(ptr: *mut u8, new_layout: Layout, flags: bindings::gf
36
37
// function safety requirement.
37
38
// - `size` is greater than 0 since it's either a `layout.size()` (which cannot be zero
38
39
// according to the function safety requirement) or a result from `next_power_of_two()`.
39
- unsafe { bindings:: krealloc ( ptr as * const core:: ffi:: c_void , size, flags) as * mut u8 }
40
+ unsafe { bindings:: krealloc ( ptr as * const core:: ffi:: c_void , size, flags. 0 ) as * mut u8 }
40
41
}
41
42
42
43
unsafe impl GlobalAlloc for KernelAllocator {
43
44
unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
44
45
// SAFETY: `ptr::null_mut()` is null and `layout` has a non-zero size by the function safety
45
46
// requirement.
46
- unsafe { krealloc_aligned ( ptr:: null_mut ( ) , layout, bindings :: GFP_KERNEL ) }
47
+ unsafe { krealloc_aligned ( ptr:: null_mut ( ) , layout, GFP_KERNEL ) }
47
48
}
48
49
49
50
unsafe fn dealloc ( & self , ptr : * mut u8 , _layout : Layout ) {
@@ -64,19 +65,13 @@ unsafe impl GlobalAlloc for KernelAllocator {
64
65
// requirement.
65
66
// - the size of `layout` is not zero because `new_size` is not zero by the function safety
66
67
// requirement.
67
- unsafe { krealloc_aligned ( ptr, layout, bindings :: GFP_KERNEL ) }
68
+ unsafe { krealloc_aligned ( ptr, layout, GFP_KERNEL ) }
68
69
}
69
70
70
71
unsafe fn alloc_zeroed ( & self , layout : Layout ) -> * mut u8 {
71
72
// SAFETY: `ptr::null_mut()` is null and `layout` has a non-zero size by the function safety
72
73
// requirement.
73
- unsafe {
74
- krealloc_aligned (
75
- ptr:: null_mut ( ) ,
76
- layout,
77
- bindings:: GFP_KERNEL | bindings:: __GFP_ZERO,
78
- )
79
- }
74
+ unsafe { krealloc_aligned ( ptr:: null_mut ( ) , layout, GFP_KERNEL | __GFP_ZERO) }
80
75
}
81
76
}
82
77
0 commit comments