From patchwork Wed Feb 13 14:54:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 10810105 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5103B1390 for ; Wed, 13 Feb 2019 14:55:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B7E12D563 for ; Wed, 13 Feb 2019 14:55:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FAD32D5BB; Wed, 13 Feb 2019 14:55:05 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 ABCE42D563 for ; Wed, 13 Feb 2019 14:55:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403943AbfBMOzD (ORCPT ); Wed, 13 Feb 2019 09:55:03 -0500 Received: from mx2.suse.de ([195.135.220.15]:60226 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2403928AbfBMOzC (ORCPT ); Wed, 13 Feb 2019 09:55:02 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id CF59CAC24; Wed, 13 Feb 2019 14:54:55 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 4F4131E09CA; Wed, 13 Feb 2019 15:54:54 +0100 (CET) From: Jan Kara To: Cc: Amir Goldstein , Konstantin Khlebnikov , Vivek Trivedi , Orion Poplawski , Jan Kara Subject: [PATCH 1/6] fanotify: Fold dequeue_event() into process_access_response() Date: Wed, 13 Feb 2019 15:54:38 +0100 Message-Id: <20190213145443.26836-2-jack@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190213145443.26836-1-jack@suse.cz> References: <20190213145443.26836-1-jack@suse.cz> 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 Fold dequeue_event() into process_access_response(). This will make changes to use of ->response field easier. Signed-off-by: Jan Kara Reviewed-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 41 ++++++++++++-------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 9c870b0d2b56..908ebc421d15 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -144,28 +144,6 @@ static int fill_event_metadata(struct fsnotify_group *group, return ret; } -static struct fanotify_perm_event_info *dequeue_event( - struct fsnotify_group *group, int fd) -{ - struct fanotify_perm_event_info *event, *return_e = NULL; - - spin_lock(&group->notification_lock); - list_for_each_entry(event, &group->fanotify_data.access_list, - fae.fse.list) { - if (event->fd != fd) - continue; - - list_del_init(&event->fae.fse.list); - return_e = event; - break; - } - spin_unlock(&group->notification_lock); - - pr_debug("%s: found return_re=%p\n", __func__, return_e); - - return return_e; -} - static int process_access_response(struct fsnotify_group *group, struct fanotify_response *response_struct) { @@ -194,14 +172,21 @@ static int process_access_response(struct fsnotify_group *group, if ((response & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT)) return -EINVAL; - event = dequeue_event(group, fd); - if (!event) - return -ENOENT; + spin_lock(&group->notification_lock); + list_for_each_entry(event, &group->fanotify_data.access_list, + fae.fse.list) { + if (event->fd != fd) + continue; - event->response = response; - wake_up(&group->fanotify_data.access_waitq); + list_del_init(&event->fae.fse.list); + event->response = response; + spin_unlock(&group->notification_lock); + wake_up(&group->fanotify_data.access_waitq); + return 0; + } + spin_unlock(&group->notification_lock); - return 0; + return -ENOENT; } static ssize_t copy_event_to_user(struct fsnotify_group *group,