diff mbox series

mm/slab: call __kmalloc_noprof() when size isn't builtin constant in kmalloc_array_noprof()

Message ID 20250301083720.380063-1-yebin@huaweicloud.com (mailing list archive)
State New
Headers show
Series mm/slab: call __kmalloc_noprof() when size isn't builtin constant in kmalloc_array_noprof() | expand

Commit Message

yebin March 1, 2025, 8:37 a.m. UTC
From: Ye Bin <yebin10@huawei.com>

If 'n' or 'size' isn't builtin constant just call __kmalloc_noprof()
in kmalloc_array_noprof().

Fixes: 7bd230a26648 ("mm/slab: enable slab allocation tagging for kmalloc and friends")
Signed-off-by: Ye Bin <yebin10@huawei.com>
---
 include/linux/slab.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Harry Yoo March 2, 2025, 1:30 p.m. UTC | #1
On Sat, Mar 01, 2025 at 04:37:20PM +0800, Ye Bin wrote:
> From: Ye Bin <yebin10@huawei.com>
> 
> If 'n' or 'size' isn't builtin constant just call __kmalloc_noprof()
> in kmalloc_array_noprof().
> 
> Fixes: 7bd230a26648 ("mm/slab: enable slab allocation tagging for kmalloc and friends")
> Signed-off-by: Ye Bin <yebin10@huawei.com>
> ---
>  include/linux/slab.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index 3b03b31831a9..0edb8363fc4f 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -947,7 +947,7 @@ static inline __alloc_size(1, 2) void *kmalloc_array_noprof(size_t n, size_t siz
>  		return NULL;
>  	if (__builtin_constant_p(n) && __builtin_constant_p(size))
>  		return kmalloc_noprof(bytes, flags);
> -	return kmalloc_noprof(bytes, flags);
> +	return __kmalloc_noprof(bytes, flags);

Can we simply call kmalloc_noprof(bytes, flags) once instead?

The compiler should know 'bytes' is a constant if both 'n' and 'size' are
constants.

>  }
>  #define kmalloc_array(...)			alloc_hooks(kmalloc_array_noprof(__VA_ARGS__))
>  
> -- 
> 2.34.1
diff mbox series

Patch

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 3b03b31831a9..0edb8363fc4f 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -947,7 +947,7 @@  static inline __alloc_size(1, 2) void *kmalloc_array_noprof(size_t n, size_t siz
 		return NULL;
 	if (__builtin_constant_p(n) && __builtin_constant_p(size))
 		return kmalloc_noprof(bytes, flags);
-	return kmalloc_noprof(bytes, flags);
+	return __kmalloc_noprof(bytes, flags);
 }
 #define kmalloc_array(...)			alloc_hooks(kmalloc_array_noprof(__VA_ARGS__))