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

Reza Arbab arbab at linux.vnet.ibm.com
Sat Oct 15 02:43:15 AEDT 2016


On Fri, Oct 14, 2016 at 11:33:12AM +1100, Michael Ellerman wrote:
>Reza Arbab <arbab at linux.vnet.ibm.com> writes:
>> 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;
	}

-- 
Reza Arbab



More information about the Linuxppc-dev mailing list