From patchwork Sat Jan 6 17:45:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10147967 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 EC7FC601A1 for ; Sat, 6 Jan 2018 17:50:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E01F026E75 for ; Sat, 6 Jan 2018 17:50:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D36B4274A3; Sat, 6 Jan 2018 17:50:02 +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.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=unavailable 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 6C3DF26E75 for ; Sat, 6 Jan 2018 17:50:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752961AbeAFRto (ORCPT ); Sat, 6 Jan 2018 12:49:44 -0500 Received: from mail-pl0-f66.google.com ([209.85.160.66]:46062 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752802AbeAFRtk (ORCPT ); Sat, 6 Jan 2018 12:49:40 -0500 Received: by mail-pl0-f66.google.com with SMTP id o2so5046924plk.12; Sat, 06 Jan 2018 09:49:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n29I5yMAz07Zumqb0y58Hk5ptHs43bWyT+75GaKrKCs=; b=X82KjBrR6ZP9o0sVdOoZ7FABpvVB+wlTxTsgbGYv3KMKm3tjKiyFAUh09pCndRuLEK q3PMehn26brK/1IUtjszChXtc97toVhKd0v22C6qFxBChW40N9Ou+DTM89+stEumyVDU q/giA5cqec07KRbQQrUcfpH4xbuLm3pJisKf4vD+OLVvH1gPnUdBygNXyzP7c+h0NlH6 S7xhEPAxyhFnHf9oWdc3UqI6zC05TtYzx+8QGjWYh36fLjO8cXZiCS2yHDePIkdnN3QS 3TNRL6n0Mk5NDqE4HyJ9hu+S/zCjLPwR6Sk4eOlW0yQpVphha7mMdp80PRbeYFB0MDcl DdQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=n29I5yMAz07Zumqb0y58Hk5ptHs43bWyT+75GaKrKCs=; b=gf/RjpVAJH7iKg4wyp6qav0QAPfGi+JKRCIAg0VeD7Ny4LxOaIWf8SDoLNO/RnAFuE la/XtGM9NCOhTWnQY8XrWc0I7hN2vxqJ8vT+CWxifUEH9AHrzEdPvi+pYVH+yy+IoPPF PJbYkFrO8nvU10ZOG9h7OX1RAz/tAdeGjJlNNcAlN282Jh/AVgDU0KMe45bgnnA/2TV3 FpKpUzIxGk8ENnufWcMqDWGqF9tq2Zwecl/oWcQU2w8zzowMjwn1y+d0+Qs+9iOIXrRq ZAz2gd5xMRPeCBRNskmlYPmrJKWo0PooWv/WfFeQprqnJlH447hGTFnX0FJQXkJaPKyL wMTg== X-Gm-Message-State: AKGB3mIIPS0AZQnWrljdJSzT7cnF7UQTCqBRfSTMd41jyp9+XbXPBurl 6lacYmrfzXbOYni8BW+fR8ci5Wiu X-Google-Smtp-Source: ACJfBouqctqynrVoFf9O1JokB8I9fOmM/Z+SjAP2wKd/u/GM3xbKgTlpl1ZRzXtpfTXabO6MoF1mSQ== X-Received: by 10.84.168.35 with SMTP id e32mr6992109plb.355.1515260978866; Sat, 06 Jan 2018 09:49:38 -0800 (PST) Received: from zzz.localdomain (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id p10sm19990234pfl.32.2018.01.06.09.49.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 Jan 2018 09:49:38 -0800 (PST) From: Eric Biggers To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Davide Libenzi , Eric Biggers Subject: [PATCH 1/3] eventfd: convert to use anon_inode_getfd() Date: Sat, 6 Jan 2018 09:45:42 -0800 Message-Id: <20180106174544.5331-2-ebiggers3@gmail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180106174544.5331-1-ebiggers3@gmail.com> References: <20180106174544.5331-1-ebiggers3@gmail.com> 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 From: Eric Biggers Nothing actually calls eventfd_file_create() besides the eventfd2() system call itself. So simplify things by folding it into the system call and using anon_inode_getfd() instead of anon_inode_getfile(). This removes over 40 lines with no change in functionality. (eventfd_file_create() was apparently added years ago for KVM irqfd's, but was never used.) Signed-off-by: Eric Biggers --- fs/eventfd.c | 53 +++++++------------------------------------------ include/linux/eventfd.h | 5 ----- 2 files changed, 7 insertions(+), 51 deletions(-) diff --git a/fs/eventfd.c b/fs/eventfd.c index 2fb4eadaa118..4167e670ed4d 100644 --- a/fs/eventfd.c +++ b/fs/eventfd.c @@ -412,72 +412,33 @@ struct eventfd_ctx *eventfd_ctx_fileget(struct file *file) } EXPORT_SYMBOL_GPL(eventfd_ctx_fileget); -/** - * eventfd_file_create - Creates an eventfd file pointer. - * @count: Initial eventfd counter value. - * @flags: Flags for the eventfd file. - * - * This function creates an eventfd file pointer, w/out installing it into - * the fd table. This is useful when the eventfd file is used during the - * initialization of data structures that require extra setup after the eventfd - * creation. So the eventfd creation is split into the file pointer creation - * phase, and the file descriptor installation phase. - * In this way races with userspace closing the newly installed file descriptor - * can be avoided. - * Returns an eventfd file pointer, or a proper error pointer. - */ -struct file *eventfd_file_create(unsigned int count, int flags) +SYSCALL_DEFINE2(eventfd2, unsigned int, count, int, flags) { - struct file *file; struct eventfd_ctx *ctx; + int fd; /* Check the EFD_* constants for consistency. */ BUILD_BUG_ON(EFD_CLOEXEC != O_CLOEXEC); BUILD_BUG_ON(EFD_NONBLOCK != O_NONBLOCK); if (flags & ~EFD_FLAGS_SET) - return ERR_PTR(-EINVAL); + return -EINVAL; ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) - return ERR_PTR(-ENOMEM); + return -ENOMEM; kref_init(&ctx->kref); init_waitqueue_head(&ctx->wqh); ctx->count = count; ctx->flags = flags; - file = anon_inode_getfile("[eventfd]", &eventfd_fops, ctx, - O_RDWR | (flags & EFD_SHARED_FCNTL_FLAGS)); - if (IS_ERR(file)) + fd = anon_inode_getfd("[eventfd]", &eventfd_fops, ctx, + O_RDWR | (flags & EFD_SHARED_FCNTL_FLAGS)); + if (fd < 0) eventfd_free_ctx(ctx); - return file; -} - -SYSCALL_DEFINE2(eventfd2, unsigned int, count, int, flags) -{ - int fd, error; - struct file *file; - - error = get_unused_fd_flags(flags & EFD_SHARED_FCNTL_FLAGS); - if (error < 0) - return error; - fd = error; - - file = eventfd_file_create(count, flags); - if (IS_ERR(file)) { - error = PTR_ERR(file); - goto err_put_unused_fd; - } - fd_install(fd, file); - return fd; - -err_put_unused_fd: - put_unused_fd(fd); - - return error; } SYSCALL_DEFINE1(eventfd, unsigned int, count) diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h index 60b2985e8a18..15826192cc23 100644 --- a/include/linux/eventfd.h +++ b/include/linux/eventfd.h @@ -30,7 +30,6 @@ struct file; #ifdef CONFIG_EVENTFD -struct file *eventfd_file_create(unsigned int count, int flags); struct eventfd_ctx *eventfd_ctx_get(struct eventfd_ctx *ctx); void eventfd_ctx_put(struct eventfd_ctx *ctx); struct file *eventfd_fget(int fd); @@ -47,10 +46,6 @@ int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *w * Ugly ugly ugly error layer to support modules that uses eventfd but * pretend to work in !CONFIG_EVENTFD configurations. Namely, AIO. */ -static inline struct file *eventfd_file_create(unsigned int count, int flags) -{ - return ERR_PTR(-ENOSYS); -} static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd) {