From patchwork Thu Oct 8 18:08:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Guzik X-Patchwork-Id: 7354541 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2D6BC9F1D5 for ; Thu, 8 Oct 2015 18:08:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 67BDE207B7 for ; Thu, 8 Oct 2015 18:08:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7E2EB207AD for ; Thu, 8 Oct 2015 18:08:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754638AbbJHSIM (ORCPT ); Thu, 8 Oct 2015 14:08:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35125 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754039AbbJHSIL (ORCPT ); Thu, 8 Oct 2015 14:08:11 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 80C4C19F200; Thu, 8 Oct 2015 18:08:11 +0000 (UTC) Received: from mguzik.localdomain (ovpn-116-48.ams2.redhat.com [10.36.116.48]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t98I88Xq021662; Thu, 8 Oct 2015 14:08:09 -0400 From: Mateusz Guzik To: Alexander Viro Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Dumazet Subject: [PATCH] fs/file.c: tidy up close_files Date: Thu, 8 Oct 2015 20:08:07 +0200 Message-Id: <1444327687-2923-1-git-send-email-mguzik@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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(); } }