* [merged] introduce-size_max.patch removed from -mm tree
@ 2012-06-01 19:32 akpm
0 siblings, 0 replies; only message in thread
From: akpm @ 2012-06-01 19:32 UTC (permalink / raw)
To: xi.wang, airlied, elder, penberg, mm-commits
The patch titled
Subject: introduce SIZE_MAX
has been removed from the -mm tree. Its filename was
introduce-size_max.patch
This patch was dropped because it was merged into mainline or a subsystem tree
The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/
------------------------------------------------------
From: Xi Wang <xi.wang@gmail.com>
Subject: 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>
---
fs/ceph/snap.c | 2 +-
include/drm/drm_mem_util.h | 4 ++--
include/linux/kernel.h | 1 +
include/linux/slab.h | 2 +-
4 files changed, 5 insertions(+), 4 deletions(-)
diff -puN fs/ceph/snap.c~introduce-size_max fs/ceph/snap.c
--- a/fs/ceph/snap.c~introduce-size_max
+++ a/fs/ceph/snap.c
@@ -331,7 +331,7 @@ static int build_snap_context(struct cep
/* alloc new snap context */
err = -ENOMEM;
- if (num > (ULONG_MAX - sizeof(*snapc)) / sizeof(u64))
+ if (num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))
goto fail;
snapc = kzalloc(sizeof(*snapc) + num*sizeof(u64), GFP_NOFS);
if (!snapc)
diff -puN include/drm/drm_mem_util.h~introduce-size_max include/drm/drm_mem_util.h
--- a/include/drm/drm_mem_util.h~introduce-size_max
+++ a/include/drm/drm_mem_util.h
@@ -31,7 +31,7 @@
static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
{
- if (size != 0 && nmemb > ULONG_MAX / size)
+ if (size != 0 && nmemb > SIZE_MAX / size)
return NULL;
if (size * nmemb <= PAGE_SIZE)
@@ -44,7 +44,7 @@ static __inline__ void *drm_calloc_large
/* Modeled after cairo's malloc_ab, it's like calloc but without the zeroing. */
static __inline__ void *drm_malloc_ab(size_t nmemb, size_t size)
{
- if (size != 0 && nmemb > ULONG_MAX / size)
+ if (size != 0 && nmemb > SIZE_MAX / size)
return NULL;
if (size * nmemb <= PAGE_SIZE)
diff -puN include/linux/kernel.h~introduce-size_max include/linux/kernel.h
--- a/include/linux/kernel.h~introduce-size_max
+++ a/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 -puN include/linux/slab.h~introduce-size_max include/linux/slab.h
--- a/include/linux/slab.h~introduce-size_max
+++ a/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);
}
_
Patches currently in -mm which might be from xi.wang@gmail.com are
origin.patch
linux-next.patch
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2012-06-01 19:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-01 19:32 [merged] introduce-size_max.patch removed from -mm tree akpm
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.