Skip to contentSkip to conversation

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

PATCH New Alexey Dobriyan 1 participant 1 message Apr 23, 2018 Proc filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---

 fs/proc/base.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
fs/proc/base.c +3 -6
@@ -2485,14 +2485,11 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
 	for (p = ents; p < last; p++) {
 		if (p->len != dentry->d_name.len)
 			continue;
-		if (!memcmp(dentry->d_name.name, p->name, p->len))
+		if (!memcmp(dentry->d_name.name, p->name, p->len)) {
+			error = proc_pident_instantiate(dir, dentry, task, p);
 			break;
+		}
 	}
-	if (p >= last)
-		goto out;
-
-	error = proc_pident_instantiate(dir, dentry, task, p);
-out:
 	put_task_struct(task);
 out_no_task:
 	return ERR_PTR(error);