Re: Linux kernel, possible useless continue



Rainer Weikusat wrote:
Ulrich Eckhardt <doomster@xxxxxxxx> writes:
Bin Chen wrote:
Below code I am curious in (A)'s continue will bring flow to (B) but
from (B) to (A) no code updates the value of both pfn and max_low_pfn.
So the condition of 'if' will always true. Is it useless?

Yes it is useless.

It is not, see below.

I'm not convinced yet, let's get this cleared up. ;)


(B) for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
pmd = one_md_table_init(pgd);
if (pfn >= max_low_pfn)
(A) continue;

You removed an important part here, the inner loop:
for (pmd_idx = 0;
pmd_idx < PTRS_PER_PMD && pfn < max_low_pfn;
^^^^^^^^^^^^^^^^^
pmd++, pmd_idx++) {

The requirement 'pfn >= max_low_pfn' for the continue is the opposite of
the one used in the loop, 'pfn < max_low_pfn'. So, if the first comparison
is true, the continue skips the inner loop, because it's all that is left
in the outer loop. If it didn't exist, the loop would only execute
its 'pmd_idx=0' statement, and then terminate because
the 'pfn<max_low_pfn' isn't given.

Just in case it wasn't clear, the if clause is indeed useless, but not for
the reasons that the OP suggested.


Uli

.



Relevant Pages