summaryrefslogtreecommitdiff
path: root/include/drm/drm_mem_util.h
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/drm/drm_mem_util.h
parent15837294d4ce717f69942f7366e99d4d1d3d9923 (diff)
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/drm/drm_mem_util.h')
-rw-r--r--include/drm/drm_mem_util.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/include/drm/drm_mem_util.h b/include/drm/drm_mem_util.h
index 6bd325fedc87..19a240446fca 100644
--- a/include/drm/drm_mem_util.h
+++ b/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(size_t nmemb, size_t size)
/* 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)