From patchwork Wed Jun 8 10:48:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 9164245 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B880F60467 for ; Wed, 8 Jun 2016 10:48:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA99B25E13 for ; Wed, 8 Jun 2016 10:48:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F7E427BE5; Wed, 8 Jun 2016 10:48:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4825D25E13 for ; Wed, 8 Jun 2016 10:48:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752543AbcFHKsN (ORCPT ); Wed, 8 Jun 2016 06:48:13 -0400 Received: from mail-pa0-f68.google.com ([209.85.220.68]:35600 "EHLO mail-pa0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751250AbcFHKsL (ORCPT ); Wed, 8 Jun 2016 06:48:11 -0400 Received: by mail-pa0-f68.google.com with SMTP id gp3so349664pac.2; Wed, 08 Jun 2016 03:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=yjha6w6vnZWelkgJV+EzCEXdKsodb3SFJ6wnHfgRPLc=; b=uaqIQE9fLyoZ7plS8jK7MkQgdNcUcnNKiypcGkNdEbAXDKHXRP33qu4M/VvlCdFBbT 1Zb2dXNiG2sgox91bl2f8QOY8JXN1gfM1ExvxfY+RqaUud1UTAKq+ebuRpY0nqc5arSS VWsEcs9L/Lqo5OiwYg4Ux2Isrjxpsjrfxh3XYDlrzy+envw09VGTRpXpMsBIQ0Lr+mkM NEW7eoDrGUyqLeq/+TcTrkOoyQOLrD8O6uCGFPNlI1RFQfu3Tt/03nS4It0fVAJ8FJSI 9oJyfF6nqf04ShksT25B/vv7+Nbj1WiKoCzw869P249HrYqJIzRI3FFjHDKEFApyIFIL TPyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=yjha6w6vnZWelkgJV+EzCEXdKsodb3SFJ6wnHfgRPLc=; b=LuywgB0hrPU4/s+quKEDV45/TdMUsi+/Uqd7fRAPv21m7ZIMTPe3eRQ2jxIExijTi6 icDpHGaa7RiakIaRILctxntpXh1kTQQE7PgesWKug6HIaGErWBfS21l0SrW4WEEBaNcv DV1sb2oSvXtcmFv+EP5FMos2FAJ2wzJ1rJZOqMi3/DQqZ7RQ/HoQ2QaXk1WptTzDrcG3 70hcdityBJHVrlMZhsqnSsvTlUFZ6QYrKye0PQGFV0QfKnMgBihnx7vJf1avspX5UQ/O QnVz9MGt/2wmMPQY12AbiTuIZ40Wih0oHFidCw+UI0H1uBYEbkCM7YClzWWIEROptA49 E0Cg== X-Gm-Message-State: ALyK8tIapbqPstUrCUMaxd4pleM1CLRmNryMwlFxBjvlj3l4h902YOl3cJnPFL6WwNMlzA== X-Received: by 10.67.16.108 with SMTP id fv12mr5175516pad.8.1465382891012; Wed, 08 Jun 2016 03:48:11 -0700 (PDT) Received: from localhost (static-ip-82-100-134-202.rev.dyxnet.com. [202.134.100.82]) by smtp.gmail.com with ESMTPSA id p1sm1392303pfb.73.2016.06.08.03.48.10 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 08 Jun 2016 03:48:10 -0700 (PDT) From: Geliang Tang To: Miklos Szeredi Cc: Geliang Tang , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] fuse: use list_first_entry_or_null Date: Wed, 8 Jun 2016 18:48:01 +0800 Message-Id: X-Mailer: git-send-email 1.9.1 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use list_first_entry_or_null() instead of list_empty() and list_entry() to simplify the code. Signed-off-by: Geliang Tang --- fs/fuse/dev.c | 7 +++---- fs/fuse/file.c | 9 ++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index cbece12..1432cf7 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1259,11 +1259,10 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, if (!fiq->connected) goto err_unlock; - if (!list_empty(&fiq->interrupts)) { - req = list_entry(fiq->interrupts.next, struct fuse_req, - intr_entry); + req = list_first_entry_or_null(&fiq->interrupts, struct fuse_req, + intr_entry); + if (req) return fuse_read_interrupt(fiq, cs, nbytes, req); - } if (forget_pending(fiq)) { if (list_empty(&fiq->pending) || fiq->forget_batch-- > 0) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 9154f86..c1d97a1 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1565,14 +1565,13 @@ static void fuse_writepage_end(struct fuse_conn *fc, struct fuse_req *req) static struct fuse_file *__fuse_write_file_get(struct fuse_conn *fc, struct fuse_inode *fi) { - struct fuse_file *ff = NULL; + struct fuse_file *ff; spin_lock(&fc->lock); - if (!list_empty(&fi->write_files)) { - ff = list_entry(fi->write_files.next, struct fuse_file, - write_entry); + ff = list_first_entry_or_null(&fi->write_files, struct fuse_file, + write_entry); + if (ff) fuse_file_get(ff); - } spin_unlock(&fc->lock); return ff;