Skip to content

Commit

Permalink
[PATCH] __kmalloc: Generate BUG if size requested is too large.
Browse files Browse the repository at this point in the history
I had an issue on ia64 where I got a bug in kernel/workqueue because
kzalloc returned a NULL pointer due to the task structure getting too big
for the slab allocator.  Usually these cases are caught by the kmalloc
macro in include/linux/slab.h.

Compilation will fail if a too big value is passed to kmalloc.

However, kzalloc uses __kmalloc which has no check for that.  This patch
makes __kmalloc bug if a too large entity is requested.

Signed-off-by: Christoph Lameter <clameter@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Christoph Lameter authored and Linus Torvalds committed Sep 23, 2005
1 parent 0cdc82e commit eafb427
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions mm/slab.c
Original file line number Diff line number Diff line change
Expand Up @@ -2907,8 +2907,7 @@ void *__kmalloc(size_t size, unsigned int __nocast flags)
* functions.
*/
cachep = __find_general_cachep(size, flags);
if (unlikely(cachep == NULL))
return NULL;
BUG_ON(!cachep); /* Allocation size too large for kmalloc */
return __cache_alloc(cachep, flags);
}
EXPORT_SYMBOL(__kmalloc);
Expand Down

0 comments on commit eafb427

Please sign in to comment.