diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2012-11-30 07:57:33 +0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2012-11-30 08:01:30 +0400 |
commit | a77cfcb429ed98845a4e4df72473b8f37acd890b (patch) | |
tree | 25a10ee731ab94f0ab4cbcd22414b5faff027768 /fs/file.c | |
parent | 21d8a15ac333b05f1fecdf9fdc30996be2e11d60 (diff) | |
download | linux-a77cfcb429ed98845a4e4df72473b8f37acd890b.tar.xz |
fix off-by-one in argument passed by iterate_fd() to callbacks
Noticed by Pavel Roskin; the thing in his patch I disagree with
was compensating for that shite in callbacks instead of fixing
it once in the iterator itself.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/file.c')
-rw-r--r-- | fs/file.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/fs/file.c b/fs/file.c index 7cb71b992603..eff23162485f 100644 --- a/fs/file.c +++ b/fs/file.c @@ -994,16 +994,18 @@ int iterate_fd(struct files_struct *files, unsigned n, const void *p) { struct fdtable *fdt; - struct file *file; int res = 0; if (!files) return 0; spin_lock(&files->file_lock); - fdt = files_fdtable(files); - while (!res && n < fdt->max_fds) { - file = rcu_dereference_check_fdtable(files, fdt->fd[n++]); - if (file) - res = f(p, file, n); + for (fdt = files_fdtable(files); n < fdt->max_fds; n++) { + struct file *file; + file = rcu_dereference_check_fdtable(files, fdt->fd[n]); + if (!file) + continue; + res = f(p, file, n); + if (res) + break; } spin_unlock(&files->file_lock); return res; |