From: Mateusz Guzik <mguzik@redhat.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Eric Dumazet <edumazet@google.com>
Subject: [PATCH] fs/file.c: tidy up close_files
Date: Thu, 8 Oct 2015 20:08:07 +0200 [thread overview]
Message-ID: <1444327687-2923-1-git-send-email-mguzik@redhat.com> (raw)
Improve consistency by reorganizing the code to use the same constructs
as do_close_on_exec.
Get rid of xchg of the file pointer. Since the table is about to be
freed there is no reason to NULLify the slot.
Get rid of the file NULL check. At this stage a bit set is supposed to
guarantee the slot is populated.
Signed-off-by: Mateusz Guzik <mguzik@redhat.com>
---
fs/file.c | 27 +++++++++++----------------
1 file changed, 11 insertions(+), 16 deletions(-)
diff --git a/fs/file.c b/fs/file.c
index 6c672ad..103d931 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -365,7 +365,7 @@ out:
return NULL;
}
-static struct fdtable *close_files(struct files_struct * files)
+static struct fdtable *close_files(struct files_struct *files)
{
/*
* It is safe to dereference the fd table without RCU or
@@ -373,24 +373,19 @@ static struct fdtable *close_files(struct files_struct * files)
* files structure.
*/
struct fdtable *fdt = rcu_dereference_raw(files->fdt);
- int i, j = 0;
+ unsigned i;
- for (;;) {
+ for (i = 0; ; i++) {
unsigned long set;
- i = j * BITS_PER_LONG;
- if (i >= fdt->max_fds)
+ unsigned fd = i * BITS_PER_LONG;
+ if (fd >= fdt->max_fds)
break;
- set = fdt->open_fds[j++];
- while (set) {
- if (set & 1) {
- struct file * file = xchg(&fdt->fd[i], NULL);
- if (file) {
- filp_close(file, files);
- cond_resched_rcu_qs();
- }
- }
- i++;
- set >>= 1;
+ set = fdt->open_fds[i];
+ for ( ; set ; fd++, set >>= 1) {
+ if (!(set & 1))
+ continue;
+ filp_close(fdt->fd[fd], files);
+ cond_resched_rcu_qs();
}
}
--
1.8.3.1
next reply other threads:[~2015-10-08 18:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-08 18:08 Mateusz Guzik [this message]
2015-10-08 19:08 ` kbuild test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1444327687-2923-1-git-send-email-mguzik@redhat.com \
--to=mguzik@redhat.com \
--cc=edumazet@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®