Skip to contentSkip to conversation

slab: alien caches must not be initialized if the allocation of the alien cache failed

PATCH New [email protected] 1 participant 1 message Jan 8, 2019

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 3/14 slab: alien caches must not be initialized if the allocation of the alien cache failed

From: Christoph Lameter <[email protected]>
Subject: slab: alien caches must not be initialized if the allocation of the alien cache failed

Callers of __alloc_alien() check for NULL. We must do the same check in __alloc_alien_cache to avoid NULL pointer dereferences on allocation failures.

Fixes 49dfc304ba241 ("slab: use the lock on alien_cache, instead of the lock on array_cache")
Fixes c8522a3a5832b ("Slab: introduce alloc_alien")
Reported-by [email protected]
Cc Pekka Enberg <[email protected]>
Cc David Rientjes <[email protected]>
Cc Joonsoo Kim <[email protected]>

---

 mm/slab.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/slab.c renamed from mm/slab.c~slab-alien-caches-must-not-be-initialized-if-the-allocation-of-the-alien-cache-failed +4 -2
@@ -666,8 +666,10 @@ static struct alien_cache *__alloc_alien
 	struct alien_cache *alc = NULL;
 
 	alc = kmalloc_node(memsize, gfp, node);
-	init_arraycache(&alc->ac, entries, batch);
-	spin_lock_init(&alc->lock);
+	if (alc) {
+		init_arraycache(&alc->ac, entries, batch);
+		spin_lock_init(&alc->lock);
+	}
 	return alc;
 }
 

_