]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
kmalloc: use posix_memalign
authorYuxuan Shui <yshuiv7@gmail.com>
Sat, 23 May 2020 16:28:52 +0000 (17:28 +0100)
committerYuxuan Shui <yshuiv7@gmail.com>
Sat, 23 May 2020 16:43:38 +0000 (17:43 +0100)
posix_memalign doesn't have the restriction that size must be a multiply
of alignment.

This also reverts the fix in commit f3fdbbfa92defb1f1d12c0038513b69b52baf33e.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
include/linux/slab.h

index 67d52c9eebcfed58bec825a66462732326e4e514..32ffa55b0833a7d928d5447544ed41553d78f27a 100644 (file)
@@ -20,12 +20,14 @@ 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(alignment, size)
-           : malloc(0);
+       if (size) {
+               size_t alignment = min(rounddown_pow_of_two(size), (size_t)PAGE_SIZE);
+               alignment = max(sizeof(void *), alignment);
+               if (posix_memalign(&p, alignment, size))
+                       p = NULL;
+       } else {
+               p = malloc(0);
+       }
        if (p && (flags & __GFP_ZERO))
                memset(p, 0, size);