Skip to contentSkip to conversation

Fix potentially derefencing uninitialized 'r'.

PATCH In review Geunsik Lim 2 participants 2 messages Feb 21, 2012 – Mar 29, 2012

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

PATCH v2 1/1 Fix potentially derefencing uninitialized 'r'.

From: Geunsik Lim <[email protected]>

v2: reorganize the code with better way to avoid compilation warning via the comment of Andrew Morton.

v1: struct memblock_region 'r' will not be initialized potentially because of while() condition in __next_mem_pfn_range()function. Solve the compilation warning related problem by initializing r data structure.

---
 mm/memblock.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
mm/memblock.c +6 -2
index 77b5f22..b8c40c5 100644
@@ -673,14 +673,18 @@ void __init_memblock __next_mem_pfn_range(int *idx, int nid,
 	struct memblock_type *type = &memblock.memory;
 	struct memblock_region *r;
 
-	while (++*idx < type->cnt) {
+	do {
 		r = &type->regions[*idx];
 
+	   if (++*idx < type->cnt) {
 		if (PFN_UP(r->base) >= PFN_DOWN(r->base + r->size))
 			continue;
 		if (nid == MAX_NUMNODES || nid == r->nid)
 			break;
-	}
+	   } else
+		break;
+	} while (1);
+
 	if (*idx >= type->cnt) {
 		*idx = -1;
 		return;
Signature · 8 lines
1.7.8.1

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 1 line · Geunsik Lim

From: Geunsik Lim <[email protected]>

The warning seems to be bogus. The only caller is for_each_mem_pfn_range and even if we had type->cnt == 0 we would return before accessing r. I guess it would be more reasonable to silent the warning by __maybe_unused.

Quoted 47 lines

v2: reorganize the code with better way to avoid compilation warning via the comment of Andrew Morton.

v1: struct memblock_region 'r' will not be initialized potentially because of while() condition in __next_mem_pfn_range()function. Solve the compilation warning related problem by initializing r data structure.

---
 mm/memblock.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
mm/memblock.c +6 -2
index 77b5f22..b8c40c5 100644
@@ -673,14 +673,18 @@ void __init_memblock __next_mem_pfn_range(int *idx, int nid,
 	struct memblock_type *type = &memblock.memory;
 	struct memblock_region *r;
 
-	while (++*idx < type->cnt) {
+	do {
 		r = &type->regions[*idx];
 
+	   if (++*idx < type->cnt) {
 		if (PFN_UP(r->base) >= PFN_DOWN(r->base + r->size))
 			continue;
 		if (nid == MAX_NUMNODES || nid == r->nid)
 			break;
-	}
+	   } else
+		break;
+	} while (1);
+
 	if (*idx >= type->cnt) {
 		*idx = -1;
 		return;
Signature · 7 lines
1.7.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>