Skip to contentSkip to conversation

SPARSEMEM incorrectly calculates section number

PATCH New Mike Kravetz 1 participant 1 message May 16, 2006

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

PATCH 1/1 SPARSEMEM incorrectly calculates section number

A bad calculation/loop in __section_nr() could result in incorrect section information being put into sysfs memory entries. This primarily impacts memory add operations as the sysfs information is used while onlining new memory.

Fix suggested by Dave Hansen.

Note that the bug may not be obvious from the patch. It actually occurs in the function's return statement:

	return (root_nr * SECTIONS_PER_ROOT) + (ms - root);

In the existing code, root_nr has already been multiplied by SECTIONS_PER_ROOT.

mm/sparse.c +2 -5
diff -Naupr linux-2.6.17-rc4-mm1/mm/sparse.c linux-2.6.17-rc4-mm1.work/mm/sparse.c
@@ -87,11 +87,8 @@ int __section_nr(struct mem_section* ms)
 	unsigned long root_nr;
 	struct mem_section* root;
 
-	for (root_nr = 0;
-	     root_nr < NR_MEM_SECTIONS;
-	     root_nr += SECTIONS_PER_ROOT) {
-		root = __nr_to_section(root_nr);
-
+	for (root_nr = 0; root_nr < NR_SECTION_ROOTS; root_nr++) {
+		root = __nr_to_section(root_nr * SECTIONS_PER_ROOT);
 		if (!root)
 			continue;