|
@@ -2270,10 +2270,11 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
|
|
|
int index = kmalloc_index(size);
|
|
|
|
|
|
if (!index)
|
|
|
- return NULL;
|
|
|
+ return ZERO_SIZE_PTR;
|
|
|
|
|
|
/* Allocation too large? */
|
|
|
- BUG_ON(index < 0);
|
|
|
+ if (index < 0)
|
|
|
+ return NULL;
|
|
|
|
|
|
#ifdef CONFIG_ZONE_DMA
|
|
|
if ((flags & SLUB_DMA)) {
|
|
@@ -2314,9 +2315,10 @@ void *__kmalloc(size_t size, gfp_t flags)
|
|
|
{
|
|
|
struct kmem_cache *s = get_slab(size, flags);
|
|
|
|
|
|
- if (s)
|
|
|
- return slab_alloc(s, flags, -1, __builtin_return_address(0));
|
|
|
- return ZERO_SIZE_PTR;
|
|
|
+ if (ZERO_OR_NULL_PTR(s))
|
|
|
+ return s;
|
|
|
+
|
|
|
+ return slab_alloc(s, flags, -1, __builtin_return_address(0));
|
|
|
}
|
|
|
EXPORT_SYMBOL(__kmalloc);
|
|
|
|
|
@@ -2325,9 +2327,10 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
|
|
|
{
|
|
|
struct kmem_cache *s = get_slab(size, flags);
|
|
|
|
|
|
- if (s)
|
|
|
- return slab_alloc(s, flags, node, __builtin_return_address(0));
|
|
|
- return ZERO_SIZE_PTR;
|
|
|
+ if (ZERO_OR_NULL_PTR(s))
|
|
|
+ return s;
|
|
|
+
|
|
|
+ return slab_alloc(s, flags, node, __builtin_return_address(0));
|
|
|
}
|
|
|
EXPORT_SYMBOL(__kmalloc_node);
|
|
|
#endif
|
|
@@ -2378,7 +2381,7 @@ void kfree(const void *x)
|
|
|
* this comparison would be true for all "negative" pointers
|
|
|
* (which would cover the whole upper half of the address space).
|
|
|
*/
|
|
|
- if ((unsigned long)x <= (unsigned long)ZERO_SIZE_PTR)
|
|
|
+ if (ZERO_OR_NULL_PTR(x))
|
|
|
return;
|
|
|
|
|
|
page = virt_to_head_page(x);
|
|
@@ -2687,8 +2690,8 @@ void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, void *caller)
|
|
|
{
|
|
|
struct kmem_cache *s = get_slab(size, gfpflags);
|
|
|
|
|
|
- if (!s)
|
|
|
- return ZERO_SIZE_PTR;
|
|
|
+ if (ZERO_OR_NULL_PTR(s))
|
|
|
+ return s;
|
|
|
|
|
|
return slab_alloc(s, gfpflags, -1, caller);
|
|
|
}
|
|
@@ -2698,8 +2701,8 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
|
|
|
{
|
|
|
struct kmem_cache *s = get_slab(size, gfpflags);
|
|
|
|
|
|
- if (!s)
|
|
|
- return ZERO_SIZE_PTR;
|
|
|
+ if (ZERO_OR_NULL_PTR(s))
|
|
|
+ return s;
|
|
|
|
|
|
return slab_alloc(s, gfpflags, node, caller);
|
|
|
}
|