[RFC/PATCH 1/3] SLAB: Add PageSlab checking to ksize()

From: Pekka J Enberg
Date: Wed May 21 2008 - 14:25:37 EST


From: Pekka Enberg <penberg@xxxxxxxxxxxxxx>

The ksize() function is meant for objects allocated from the slab caches, not
for arbitrary objects. Add a BUG_ON() to enforce that.

Cc: Christoph Lameter <clameter@xxxxxxx>
Cc: Matt Mackall <mpm@xxxxxxxxxxx>
Cc: Paul Mundt <lethal@xxxxxxxxxxxx>
Cc: David Howells <dhowells@xxxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxxxxxx>
---
mm/slab.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/mm/slab.c b/mm/slab.c
index 06236e4..b98bb7c 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -4472,10 +4472,14 @@ const struct seq_operations slabstats_op = {
*/
size_t ksize(const void *objp)
{
+ struct page *page;
+
BUG_ON(!objp);
if (unlikely(objp == ZERO_SIZE_PTR))
return 0;

- return obj_size(virt_to_cache(objp));
+ page = virt_to_page(objp);
+ BUG_ON(!PageSlab(page));
+ return obj_size(page_get_cache(page));
}
EXPORT_SYMBOL(ksize);
--
1.5.2.5

--
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/