lkml.org 
[lkml]   [2012]   [Feb]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] slab: warning if total alloc size overflow
Date
Before, if the total alloc size is overflow,
we just return NULL like alloc fail. But they
are two different type problems. The former looks
more like a programming problem. So add a warning
here.

Signed-off-by: Yang Bai <hamo.by@gmail.com>
---
include/linux/slab.h | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 573c809..5865237 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -242,8 +242,10 @@ size_t ksize(const void *);
*/
static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
{
- if (size != 0 && n > ULONG_MAX / size)
+ if (size != 0 && n > ULONG_MAX / size) {
+ WARN(1, "Alloc memory size (%lu * %lu) overflow.", n, size);
return NULL;
+ }
return __kmalloc(n * size, flags | __GFP_ZERO);
}

--
1.7.9


\
 
 \ /
  Last update: 2012-02-14 08:31    [W:0.157 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site