diff --git a/mm/slab.c b/mm/slab.c
index 910df63268314cc25b6a2db2fd0e6e4160488572..a98f8db93670379bae9bcbcc68a38427dd174fd4 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3289,6 +3289,7 @@ static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags,
 	void *obj;
 	int x;
 
+	VM_BUG_ON(nodeid > num_online_nodes());
 	n = cachep->node[nodeid];
 	BUG_ON(!n);