mm/slab: call kmalloc_noprof() unconditionally in kmalloc_array_noprof()
authorYe Bin <yebin10@huawei.com>
Sat, 1 Mar 2025 08:37:20 +0000 (16:37 +0800)
committerVlastimil Babka <vbabka@suse.cz>
Wed, 5 Mar 2025 09:03:31 +0000 (10:03 +0100)
If 'n' or 'size' isn't builtin constant, we used to call __kmalloc()
before commit 7bd230a26648 ("mm/slab: enable slab allocation tagging for
kmalloc and friends"), which inadvertedly changed both paths to
kmalloc_noprof().

As Harry Yoo points out we can just call kmalloc_noprof()
unconditionally. If the compiler knows n and size are constants it
doesn't guarantee that bytes will be also seen as constant, and that is
the important test in kmalloc_noprof() anyway, so we can just defer to
it always.

[ vbabka@suse.cz: change as Harry suggested and adjust commit log ]

Fixes: 7bd230a26648 ("mm/slab: enable slab allocation tagging for kmalloc and friends")
Signed-off-by: Ye Bin <yebin10@huawei.com>
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
include/linux/slab.h

index 09eedaecf1205672bb2e7c8cd57ae8fccebc2737..ab05a143d09a27e87959632729cc6fe791a34d9e 100644 (file)
@@ -941,8 +941,6 @@ static inline __alloc_size(1, 2) void *kmalloc_array_noprof(size_t n, size_t siz
 
        if (unlikely(check_mul_overflow(n, size, &bytes)))
                return NULL;
-       if (__builtin_constant_p(n) && __builtin_constant_p(size))
-               return kmalloc_noprof(bytes, flags);
        return kmalloc_noprof(bytes, flags);
 }
 #define kmalloc_array(...)                     alloc_hooks(kmalloc_array_noprof(__VA_ARGS__))