From: Kristian Høgsberg Date: Mon, 8 Jun 2009 15:50:41 +0000 (+1000) Subject: drm_calloc_large: check right size, check integer overflow, use GFP_ZERO X-Git-Tag: v2.6.31-rc1~294^2~11 X-Git-Url: http://ftp.safe.ca/?a=commitdiff_plain;h=fbe0efb869efde8d847ede3a925230ef88910086;p=safe%2Fjmp%2Flinux-2.6 drm_calloc_large: check right size, check integer overflow, use GFP_ZERO Previously we would check size instead of size * nmemb, and so would never hit the vmalloc path. Also add integer overflow check as in kcalloc, and allocate GFP_ZERO pages instead of memset()ing them. Signed-off-by: Kristian Høgsberg Signed-off-by: Dave Airlie --- diff --git a/include/drm/drmP.h b/include/drm/drmP.h index afc2168..1cc51a0 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -1573,18 +1573,14 @@ static __inline__ void *drm_calloc(size_t nmemb, size_t size, int area) static __inline__ void *drm_calloc_large(size_t nmemb, size_t size) { - u8 *addr; - - if (size <= PAGE_SIZE) + if (size * nmemb <= PAGE_SIZE) return kcalloc(nmemb, size, GFP_KERNEL); - addr = vmalloc(nmemb * size); - if (!addr) + if (size != 0 && nmemb > ULONG_MAX / size) return NULL; - memset(addr, 0, nmemb * size); - - return addr; + return __vmalloc(size * nmemb, + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL); } static __inline void drm_free_large(void *ptr)