Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

proc: skip branch in /proc/*/* lookup

Code is structured like this:

for ( ... p < last; p++) {
if (memcmp == 0)
break;
}
if (p >= last)
ERROR
OK

gcc doesn't see that if if lookup succeeds than post loop branch will
never be taken and skip it.

[akpm@linux-foundation.org: proc_pident_instantiate() no longer takes an inode*]
Link: http://lkml.kernel.org/r/20180423213954.GD9043@avx2
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Alexey Dobriyan and committed by
Linus Torvalds
26b95137 37a4094e

+3 -6
+3 -6
fs/proc/base.c
··· 2439 2439 for (p = ents; p < last; p++) { 2440 2440 if (p->len != dentry->d_name.len) 2441 2441 continue; 2442 - if (!memcmp(dentry->d_name.name, p->name, p->len)) 2442 + if (!memcmp(dentry->d_name.name, p->name, p->len)) { 2443 + res = proc_pident_instantiate(dentry, task, p); 2443 2444 break; 2445 + } 2444 2446 } 2445 - if (p >= last) 2446 - goto out; 2447 - 2448 - res = proc_pident_instantiate(dentry, task, p); 2449 - out: 2450 2447 put_task_struct(task); 2451 2448 out_no_task: 2452 2449 return res;