Skip to contentSkip to conversation

mm: Make it easier to catch NULL cache names

PATCH In review Benjamin Herrenschmidt 3 participants 5 messages Jul 28, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: Make it easier to catch NULL cache names

Right now, if you inadvertently pass NULL to kmem_cache_create() at boot time, it crashes much later after boot somewhere deep inside sysfs which makes it very non obvious to figure out what's going on.

---

Yes, I did hit that :-) Something in ppc land using an array of caches and got the names array out of sync with changes to the list of indices.

mm/slub.c +2 -0
index b9f1491..b5b5653 100644
@@ -3292,6 +3292,8 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
 {
 	struct kmem_cache *s;
 
+	BUG_ON(name == NULL);
+
 	down_write(&slub_lock);
 	s = find_mergeable(size, align, flags, name, ctor);
 	if (s) {
Signature · 9 lines
1.6.1.2.14.gf26b5



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 4 lines · Benjamin Herrenschmidt

Right now, if you inadvertently pass NULL to kmem_cache_create() at boot time, it crashes much later after boot somewhere deep inside sysfs which makes it very non obvious to figure out what's going on.

Please don't do BUG_ON() when there are alternatives.

In this case, something like

	if (WARN_ON(!name))
		return NULL;

would probably have worked too.

Linus

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 7 lines · Linus Torvalds
Quoted 4 lines · Benjamin Herrenschmidt

Right now, if you inadvertently pass NULL to kmem_cache_create() at boot time, it crashes much later after boot somewhere deep inside sysfs which makes it very non obvious to figure out what's going on.

Quoted 8 lines

Please don't do BUG_ON() when there are alternatives.

In this case, something like

	if (WARN_ON(!name))
		return NULL;

would probably have worked too.

Fair enough.. I'll send a new patch.

Cheers,
Ben.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 8 lines

Please don't do BUG_ON() when there are alternatives.

In this case, something like

	if (WARN_ON(!name))
		return NULL;

would probably have worked too.

Fair enough.. I'll send a new patch.

Actually needs goto err, not return NULL, to appropriately panic when SLAB_PANIC is set.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 9 lines · David Rientjes
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 7 lines

Please don't do BUG_ON() when there are alternatives.

In this case, something like

	if (WARN_ON(!name))
		return NULL;
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

would probably have worked too.

Fair enough.. I'll send a new patch.

Actually needs goto err, not return NULL, to appropriately panic when SLAB_PANIC is set.

Rats ! Why is it the trivial ones that are sooo hard :-)

New patch will have to wait til tomorrow, on my way home now.

Cheers,
Ben.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>