From: Milton Miller Date: Thu, 24 Jul 2008 04:28:20 +0000 (-0700) Subject: kcalloc: remove runtime division X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9ca908f47bc784c90e17a553ce33e756c73feac4;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git kcalloc: remove runtime division While in all cases in the kernel we know the size of the elements to be created, we don't always know the count of elements. By commuting the size and count in the overflow check, the compiler can reduce the runtime division of size_t with a compare to a (unique) constant in these cases. Signed-off-by: Milton Miller Cc: Takashi Iwai Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/include/linux/slab.h b/include/linux/slab.h index 9aa90a6f20e0..41103910f8a2 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -180,7 +180,7 @@ size_t ksize(const void *); */ static inline void *kcalloc(size_t n, size_t size, gfp_t flags) { - if (n != 0 && size > ULONG_MAX / n) + if (size != 0 && n > ULONG_MAX / size) return NULL; return __kmalloc(n * size, flags | __GFP_ZERO); }