Merge pull request #30 from yshui/master

Make sure aligned_alloc size is a multiply of alignment
This commit is contained in:
koverstreet 2020-05-21 16:34:58 -04:00 committed by GitHub
commit e96c6508cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,9 +20,11 @@ static inline void *kmalloc(size_t size, gfp_t flags)
run_shrinkers();
size_t alignment = min(rounddown_pow_of_two(size),
(size_t)PAGE_SIZE);
size = roundup(size, alignment);
p = size
? aligned_alloc(min(rounddown_pow_of_two(size),
(size_t)PAGE_SIZE), size)
? aligned_alloc(alignment, size)
: malloc(0);
if (p && (flags & __GFP_ZERO))
memset(p, 0, size);