[PATCH] slub: slub_def.h: needs additional check for "index"

From: Maxin John
Date: Fri May 06 2011 - 14:28:11 EST


In slub_def.h file, the kmalloc_index() may return -1 for some special cases.
If that negative return value gets assigned to "index", it might lead to issues
later as the variable "index" is used as index to array "kmalloc_caches" in :

return kmalloc_caches[index];

Please let me know your comments.

Signed-off-by: Maxin B. John <maxin.john@xxxxxxxxx>
---
diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
index 45ca123..3db4b33 100644
--- a/include/linux/slub_def.h
+++ b/include/linux/slub_def.h
@@ -211,7 +211,7 @@ static __always_inline struct kmem_cache
*kmalloc_slab(size_t size)
{
int index = kmalloc_index(size);

- if (index == 0)
+ if (index <= 0)
return NULL;

return kmalloc_caches[index];
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/