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 <krh@redhat.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
committed by
Dave Airlie
parent
61f11699e7
commit
fbe0efb869
@@ -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)
|
static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
|
||||||
{
|
{
|
||||||
u8 *addr;
|
if (size * nmemb <= PAGE_SIZE)
|
||||||
|
|
||||||
if (size <= PAGE_SIZE)
|
|
||||||
return kcalloc(nmemb, size, GFP_KERNEL);
|
return kcalloc(nmemb, size, GFP_KERNEL);
|
||||||
|
|
||||||
addr = vmalloc(nmemb * size);
|
if (size != 0 && nmemb > ULONG_MAX / size)
|
||||||
if (!addr)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memset(addr, 0, nmemb * size);
|
return __vmalloc(size * nmemb,
|
||||||
|
GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
|
||||||
return addr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline void drm_free_large(void *ptr)
|
static __inline void drm_free_large(void *ptr)
|
||||||
|
Reference in New Issue
Block a user