From: Adrian Bunk Date: Wed, 22 Mar 2006 08:08:09 +0000 (-0800) Subject: [PATCH] kcalloc(): INT_MAX -> ULONG_MAX X-Git-Tag: v2.6.17-rc1~1129^2~72 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b50ec7d8070ae7a39fe78e65a8812bbc3ca2f7ac;p=linux-2.6 [PATCH] kcalloc(): INT_MAX -> ULONG_MAX Since size_t has the same size as a long on all architectures, it's enough for overflow checks to check against ULONG_MAX. This change could allow a compiler better optimization (especially in the n=1 case). The practical effect seems to be positive, but quite small: text data bss dec hex filename 21762380 5859870 1848928 29471178 1c1b1ca vmlinux-old 21762211 5859870 1848928 29471009 1c1b121 vmlinux-patched Signed-off-by: Adrian Bunk Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/include/linux/slab.h b/include/linux/slab.h index 8cf52939d0..38bed95dda 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -118,7 +118,7 @@ extern void *kzalloc(size_t, gfp_t); */ static inline void *kcalloc(size_t n, size_t size, gfp_t flags) { - if (n != 0 && size > INT_MAX / n) + if (n != 0 && size > ULONG_MAX / n) return NULL; return kzalloc(n * size, flags); }