summaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorXi Wang <xi.wang@gmail.com>2012-05-31 16:26:04 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2012-05-31 17:49:26 -0700
commita3860c1c5dd1137db23d7786d284939c5761d517 (patch)
tree48d688c6c391ef45f79bdd60815450ca06c5cc1a /include/linux
parent15837294d4ce717f69942f7366e99d4d1d3d9923 (diff)
downloadlinux-stable-a3860c1c5dd1137db23d7786d284939c5761d517.tar.gz
linux-stable-a3860c1c5dd1137db23d7786d284939c5761d517.tar.bz2
linux-stable-a3860c1c5dd1137db23d7786d284939c5761d517.zip
introduce SIZE_MAX
ULONG_MAX is often used to check for integer overflow when calculating allocation size. While ULONG_MAX happens to work on most systems, there is no guarantee that `size_t' must be the same size as `long'. This patch introduces SIZE_MAX, the maximum value of `size_t', to improve portability and readability for allocation size validation. Signed-off-by: Xi Wang <xi.wang@gmail.com> Acked-by: Alex Elder <elder@dreamhost.com> Cc: David Airlie <airlied@linux.ie> Cc: Pekka Enberg <penberg@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/kernel.h1
-rw-r--r--include/linux/slab.h2
2 files changed, 2 insertions, 1 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index ec55a3c8ba77..e07f5e0c5df4 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -35,6 +35,7 @@
#define LLONG_MAX ((long long)(~0ULL>>1))
#define LLONG_MIN (-LLONG_MAX - 1)
#define ULLONG_MAX (~0ULL)
+#define SIZE_MAX (~(size_t)0)
#define STACK_MAGIC 0xdeadbeef
diff --git a/include/linux/slab.h b/include/linux/slab.h
index a595dce6b0c7..67d5d94b783a 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -242,7 +242,7 @@ size_t ksize(const void *);
*/
static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
{
- if (size != 0 && n > ULONG_MAX / size)
+ if (size != 0 && n > SIZE_MAX / size)
return NULL;
return __kmalloc(n * size, flags);
}