linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] slab: warning if total alloc size overflow
@ 2012-02-14  7:28 Yang Bai
  2012-02-14  7:31 ` Pekka Enberg
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Yang Bai @ 2012-02-14  7:28 UTC (permalink / raw)
  To: cl, penberg, mpm; +Cc: linux-mm, linux-kernel, Yang Bai

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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-02-14 15:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-14  7:28 [PATCH] slab: warning if total alloc size overflow Yang Bai
2012-02-14  7:31 ` Pekka Enberg
2012-02-14  7:51   ` Yang Bai
2012-02-14  8:10     ` Pekka Enberg
2012-02-14 15:04   ` Christoph Lameter
2012-02-14  8:53 ` Andrew Morton
2012-02-14  9:43   ` Yang Bai
2012-02-14 15:07   ` Christoph Lameter
2012-02-14 15:03 ` Christoph Lameter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).