Skip to contentSkip to conversation

powerpc/mm: simplify loop control in parse_numa_properties()

PATCH Applied Reza Arbab 3 participants 4 messages Oct 13, 2016 – Feb 1, 2017 PowerPC

lore
Share & tools
lore

Reza Arbab

author
#0 lore raw

PATCH 1/1 powerpc/mm: simplify loop control in parse_numa_properties()

The flow of the main loop in parse_numa_properties() is overly complicated. Simplify it to be less confusing and easier to read. No functional change.

---
 arch/powerpc/mm/numa.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
arch/powerpc/mm/numa.c +3 -8
index d7ac419..b30ced8 100644
@@ -786,14 +786,9 @@ new_range:
 		fake_numa_create_new_node(((start + size) >> PAGE_SHIFT), &nid);
 		node_set_online(nid);
 
-		if (!(size = numa_enforce_memory_limit(start, size))) {
-			if (--ranges)
-				goto new_range;
-			else
-				continue;
-		}
-
-		memblock_set_node(start, size, &memblock.memory, nid);
+		size = numa_enforce_memory_limit(start, size);
+		if (size)
+			memblock_set_node(start, size, &memblock.memory, nid);
 
 		if (--ranges)
 			goto new_range;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 3 lines · Reza Arbab

The flow of the main loop in parse_numa_properties() is overly complicated. Simplify it to be less confusing and easier to read. No functional change.

I think you're right, but it's not obvious from the diff. Please explain in more detail why the old and new code is equivalent.

cheers

author
#2 lore raw
Quoted 7 lines · Michael Ellerman
Quoted 3 lines · Reza Arbab

The flow of the main loop in parse_numa_properties() is overly complicated. Simplify it to be less confusing and easier to read. No functional change.

I think you're right, but it's not obvious from the diff. Please explain in more detail why the old and new code is equivalent.

I'm not sure if being this verbose helps, but...

The end of the main loop in parse_numa_properties() looks like this:

	for_each_node_by_type(...) {
		...

		if (!condition) {
			if (--ranges)
				goto new_range;
			else
				continue;
		}

		statement();

		if (--ranges)
			goto new_range;
		/* else
		 *	continue; <- implicit, this is the end of the loop
		 */
	}

The only effect of !condition is to skip execution of statement(). This can be rewritten in a simpler way:

	for_each_node_by_type(...) {
		...

		if (condition)
			statement();

		if (--ranges)
			goto new_range;
	}
Signature · 1 line
Reza Arbab