aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMilton Miller <miltonm@bga.com>2008-07-24 00:28:20 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-24 13:47:21 -0400
commit9ca908f47bc784c90e17a553ce33e756c73feac4 (patch)
tree2b6752e655484b1936ee1d410f272f9ff8b0305d /include
parent5c755e9fd813810680abd56ec09a5f90143e815b (diff)
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 <miltonm@bga.com> Cc: Takashi Iwai <tiwai@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/slab.h2
1 files changed, 1 insertions, 1 deletions
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 *);
180 */ 180 */
181static inline void *kcalloc(size_t n, size_t size, gfp_t flags) 181static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
182{ 182{
183 if (n != 0 && size > ULONG_MAX / n) 183 if (size != 0 && n > ULONG_MAX / size)
184 return NULL; 184 return NULL;
185 return __kmalloc(n * size, flags | __GFP_ZERO); 185 return __kmalloc(n * size, flags | __GFP_ZERO);
186} 186}