Skip to content

Commit bac5f5d

Browse files
Alexey Dobriyantorvalds
authored andcommitted
fs/proc/base.c: save decrement during lookup/readdir in /proc/$PID
Comparison for "<" works equally well as comparison for "<=" but one SUB/LEA is saved (no, it is not optimised away, at least here). Link: http://lkml.kernel.org/r/20161122195143.GA29812@avx2 Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 209b14d commit bac5f5d

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎fs/proc/base.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,14 +2412,14 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
24122412
* Yes, it does not scale. And it should not. Don't add
24132413
* new entries into /proc/<tgid>/ without very good reasons.
24142414
*/
2415-
last = &ents[nents - 1];
2416-
for (p = ents; p <= last; p++) {
2415+
last = &ents[nents];
2416+
for (p = ents; p < last; p++) {
24172417
if (p->len != dentry->d_name.len)
24182418
continue;
24192419
if (!memcmp(dentry->d_name.name, p->name, p->len))
24202420
break;
24212421
}
2422-
if (p > last)
2422+
if (p >= last)
24232423
goto out;
24242424

24252425
error = proc_pident_instantiate(dir, dentry, task, p);
@@ -2444,7 +2444,7 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
24442444
if (ctx->pos >= nents + 2)
24452445
goto out;
24462446

2447-
for (p = ents + (ctx->pos - 2); p <= ents + nents - 1; p++) {
2447+
for (p = ents + (ctx->pos - 2); p < ents + nents; p++) {
24482448
if (!proc_fill_cache(file, ctx, p->name, p->len,
24492449
proc_pident_instantiate, task, p))
24502450
break;

0 commit comments

Comments
 (0)