unsigned int max_fd)
{
struct file *file;
+ struct fdtable *fdt;
unsigned n;
spin_lock(&files->file_lock);
- n = last_fd(files_fdtable(files));
+ fdt = files_fdtable(files);
+ n = last_fd(fdt);
max_fd = min(max_fd, n);
- for (; fd <= max_fd; fd++) {
+ for (fd = find_next_bit(fdt->open_fds, max_fd + 1, fd);
+ fd <= max_fd;
+ fd = find_next_bit(fdt->open_fds, max_fd + 1, fd + 1)) {
file = file_close_fd_locked(files, fd);
if (file) {
spin_unlock(&files->file_lock);
filp_close(file, files);
cond_resched();
spin_lock(&files->file_lock);
+ fdt = files_fdtable(files);
} else if (need_resched()) {
spin_unlock(&files->file_lock);
cond_resched();
spin_lock(&files->file_lock);
+ fdt = files_fdtable(files);
}
}
spin_unlock(&files->file_lock);