Skip to contentSkip to conversation

percpu: off by one in BUG_ON()

PATCH Applied Dan Carpenter 2 participants 2 messages Oct 29, 2014

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

PATCH 1/1 percpu: off by one in BUG_ON()

The unit_map[] array has "nr_cpu_ids" number of elements. It's allocated a few lines earlier in the function. So this test should be

Quoted 1 line

= instead of >.

---
Static checker stuff. Not tested.

mm/percpu.c +1 -1
index 014bab6..d39e2f4 100644
@@ -1591,7 +1591,7 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
 			if (cpu = NR_CPUS)
 				continue;
 
-			PCPU_SETUP_BUG_ON(cpu > nr_cpu_ids);
+			PCPU_SETUP_BUG_ON(cpu >= nr_cpu_ids);
 			PCPU_SETUP_BUG_ON(!cpu_possible(cpu));
 			PCPU_SETUP_BUG_ON(unit_map[cpu] != UINT_MAX);
 
maintainer Applied
#1 lore raw
Quoted 5 lines · Dan Carpenter

The unit_map[] array has "nr_cpu_ids" number of elements. It's allocated a few lines earlier in the function. So this test should be

Quoted 1 line

= instead of >.

Applied to percpu/for-3.19.

Thanks.

Signature · 1 line
tejun