diff options
author | Yuxuan Shui <yshuiv7@gmail.com> | 2020-05-21 14:36:00 +0100 |
---|---|---|
committer | Yuxuan Shui <yshuiv7@gmail.com> | 2020-05-21 14:36:00 +0100 |
commit | f3fdbbfa92defb1f1d12c0038513b69b52baf33e (patch) | |
tree | aea2ab05d5a91230ba59f3ea59567891f9f0dc72 /include/linux | |
parent | 6a765fd0852e38d0dceebeceab8821ef0463ac11 (diff) |
Make sure aligned_alloc size is a multiply of alignment
Fix a ASan complaint.
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/slab.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/include/linux/slab.h b/include/linux/slab.h index d77b7683..67d52c9e 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -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); |