From patchwork Fri May 8 15:36:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 206939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 024B8C38A2A for ; Fri, 8 May 2020 15:38:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CEAD4207DD for ; Fri, 8 May 2020 15:38:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="srCBSzZw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727837AbgEHPgl (ORCPT ); Fri, 8 May 2020 11:36:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726636AbgEHPgk (ORCPT ); Fri, 8 May 2020 11:36:40 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE5C2C061A0C; Fri, 8 May 2020 08:36:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=6EYCyTrFxa9+uQHjnJOrj9adSL4387IIusv8CGn+u5c=; b=srCBSzZwpa/R8vT9FGb8MSiNzT Qqn1uYSRLBeu5tyD/4XSsT0mYDn4lLbRdOf4moLFs/SGTwShV9DVJofzbIoBQmBoBJiCsWqkwHDqS 6ifMQM06Uy05ogqQUznA5cW2YOrFFIeJ5LsIJcSd7jpMi1tvx7P3FtVwCveS1aikMR4WbSiyK0LT7 /969LGJr0wCQLH7KzkFKs+MMOy8JW/daxQoggK4NgoMsrtAgwQEv7YMXtPvYU5W4jXBe7XEl/OQ1p uHAT3dFwh9mYW4W9MObM6CGHUmn/fWgH3Ylz2U2jryjURgP+RE+6QKq4EsiRP1gW7DDlgIA4OYoga wlnUSMRw==; Received: from [2001:4bb8:180:9d3f:90d7:9df8:7cd:3504] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX53I-00047B-4u; Fri, 08 May 2020 15:36:40 +0000 From: Christoph Hellwig To: Alexander Viro Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 01/12] fd: add a new __anon_inode_getfd helper Date: Fri, 8 May 2020 17:36:23 +0200 Message-Id: <20200508153634.249933-2-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508153634.249933-1-hch@lst.de> References: <20200508153634.249933-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add a helper that is equivalent to anon_inode_getfd minus the final fd_install. Signed-off-by: Christoph Hellwig --- fs/anon_inodes.c | 41 ++++++++++++++++++++++--------------- include/linux/anon_inodes.h | 2 ++ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c index 89714308c25b8..1b2acd2bbaa32 100644 --- a/fs/anon_inodes.c +++ b/fs/anon_inodes.c @@ -106,6 +106,26 @@ struct file *anon_inode_getfile(const char *name, } EXPORT_SYMBOL_GPL(anon_inode_getfile); +int __anon_inode_getfd(const char *name, const struct file_operations *fops, + void *priv, int flags, struct file **file) +{ + int fd; + + fd = get_unused_fd_flags(flags); + if (fd < 0) + return fd; + + *file = anon_inode_getfile(name, fops, priv, flags); + if (IS_ERR(*file)) + goto err_put_unused_fd; + return fd; + +err_put_unused_fd: + put_unused_fd(fd); + return PTR_ERR(*file); +} +EXPORT_SYMBOL_GPL(__anon_inode_getfd); + /** * anon_inode_getfd - creates a new file instance by hooking it up to an * anonymous inode, and a dentry that describe the "class" @@ -125,26 +145,13 @@ EXPORT_SYMBOL_GPL(anon_inode_getfile); int anon_inode_getfd(const char *name, const struct file_operations *fops, void *priv, int flags) { - int error, fd; struct file *file; + int fd; - error = get_unused_fd_flags(flags); - if (error < 0) - return error; - fd = error; - - file = anon_inode_getfile(name, fops, priv, flags); - if (IS_ERR(file)) { - error = PTR_ERR(file); - goto err_put_unused_fd; - } - fd_install(fd, file); - + fd = __anon_inode_getfd(name, fops, priv, flags, &file); + if (fd >= 0) + fd_install(fd, file); return fd; - -err_put_unused_fd: - put_unused_fd(fd); - return error; } EXPORT_SYMBOL_GPL(anon_inode_getfd); diff --git a/include/linux/anon_inodes.h b/include/linux/anon_inodes.h index d0d7d96261adf..338449d06b617 100644 --- a/include/linux/anon_inodes.h +++ b/include/linux/anon_inodes.h @@ -16,6 +16,8 @@ struct file *anon_inode_getfile(const char *name, void *priv, int flags); int anon_inode_getfd(const char *name, const struct file_operations *fops, void *priv, int flags); +int __anon_inode_getfd(const char *name, const struct file_operations *fops, + void *priv, int flags, struct file **file); #endif /* _LINUX_ANON_INODES_H */ From patchwork Fri May 8 15:36:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 206940 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D057C54E4A for ; Fri, 8 May 2020 15:38:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4EBB821841 for ; Fri, 8 May 2020 15:38:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="UNM07rxT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728547AbgEHPiN (ORCPT ); Fri, 8 May 2020 11:38:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728174AbgEHPgt (ORCPT ); Fri, 8 May 2020 11:36:49 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 035BDC061A0C; Fri, 8 May 2020 08:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=MVpXPi4fO9ek2hxfJ7eaB5mhfWvQarx43ZgTOZ4t1BM=; b=UNM07rxTMrjSKj57obB1kc0GKN 4c/P3xwFW5d9k3Hfi744eTkLYszdumNcpfrOjsxrJ9UyA5pDgJlACed00AREq1SZCfAHi0YTUfXeL 1a3vaAcVbG4IQqGt9D66OEKVcFQkxqBxp4rUGWmpPQER44ale5ue+RbbzOgzgKvdrdhoJt3D2NNxV 1eAPLhsMIzXbIHLL3++l6NlGgamQ555CXKlTkvYsF5jaAuaiGhVap01g1xYLqxcArTXcJZqmFMBoz IZqNqIah5HvQMt9E9lRkiTzhTJQ5P5+JS/j09j+PuFEw8yw+wQnDHAw0xudwrm7AWdgH4vpWmQFKP ZOHP/mFw==; Received: from [2001:4bb8:180:9d3f:90d7:9df8:7cd:3504] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX53Q-00049Y-EX; Fri, 08 May 2020 15:36:48 +0000 From: Christoph Hellwig To: Alexander Viro Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 04/12] bpf: use __anon_inode_getfd Date: Fri, 8 May 2020 17:36:26 +0200 Message-Id: <20200508153634.249933-5-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508153634.249933-1-hch@lst.de> References: <20200508153634.249933-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Use __anon_inode_getfd instead of opencoding the logic using get_unused_fd_flags + anon_inode_getfile. Also switch the bpf_link_new_file calling conventions to match __anon_inode_getfd. Signed-off-by: Christoph Hellwig --- include/linux/bpf.h | 2 +- kernel/bpf/cgroup.c | 6 +++--- kernel/bpf/syscall.c | 31 +++++++++---------------------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index fd2b2322412d7..539649fe8b885 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1103,7 +1103,7 @@ void bpf_link_cleanup(struct bpf_link *link, struct file *link_file, void bpf_link_inc(struct bpf_link *link); void bpf_link_put(struct bpf_link *link); int bpf_link_new_fd(struct bpf_link *link); -struct file *bpf_link_new_file(struct bpf_link *link, int *reserved_fd); +int bpf_link_new_file(struct bpf_link *link, struct file **link_file); struct bpf_link *bpf_link_get_from_fd(u32 ufd); int bpf_obj_pin_user(u32 ufd, const char __user *pathname); diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index cb305e71e7deb..8605287adcd9e 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -836,10 +836,10 @@ int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) link->cgroup = cgrp; link->type = attr->link_create.attach_type; - link_file = bpf_link_new_file(&link->link, &link_fd); - if (IS_ERR(link_file)) { + link_fd = bpf_link_new_file(&link->link, &link_file); + if (link_fd < 0) { kfree(link); - err = PTR_ERR(link_file); + err = link_fd; goto out_put_cgroup; } diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 64783da342020..cb2364e17423c 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2307,23 +2307,10 @@ int bpf_link_new_fd(struct bpf_link *link) * complicated and expensive operations and should be delayed until all the fd * reservation and anon_inode creation succeeds. */ -struct file *bpf_link_new_file(struct bpf_link *link, int *reserved_fd) +int bpf_link_new_file(struct bpf_link *link, struct file **file) { - struct file *file; - int fd; - - fd = get_unused_fd_flags(O_CLOEXEC); - if (fd < 0) - return ERR_PTR(fd); - - file = anon_inode_getfile("bpf_link", &bpf_link_fops, link, O_CLOEXEC); - if (IS_ERR(file)) { - put_unused_fd(fd); - return file; - } - - *reserved_fd = fd; - return file; + return __anon_inode_getfd("bpf_link", &bpf_link_fops, link, O_CLOEXEC, + file); } struct bpf_link *bpf_link_get_from_fd(u32 ufd) @@ -2406,10 +2393,10 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog) } bpf_link_init(&link->link, &bpf_tracing_link_lops, prog); - link_file = bpf_link_new_file(&link->link, &link_fd); - if (IS_ERR(link_file)) { + link_fd = bpf_link_new_file(&link->link, &link_file); + if (link_fd < 0) { kfree(link); - err = PTR_ERR(link_file); + err = link_fd; goto out_put_prog; } @@ -2520,10 +2507,10 @@ static int bpf_raw_tracepoint_open(const union bpf_attr *attr) bpf_link_init(&link->link, &bpf_raw_tp_lops, prog); link->btp = btp; - link_file = bpf_link_new_file(&link->link, &link_fd); - if (IS_ERR(link_file)) { + link_fd = bpf_link_new_file(&link->link, &link_file); + if (link_fd < 0) { kfree(link); - err = PTR_ERR(link_file); + err = link_fd; goto out_put_btp; } From patchwork Fri May 8 15:36:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 206944 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8980EC47247 for ; Fri, 8 May 2020 15:37:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6157D24955 for ; Fri, 8 May 2020 15:37:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="r/T2Qu4D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728289AbgEHPg7 (ORCPT ); Fri, 8 May 2020 11:36:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728264AbgEHPgy (ORCPT ); Fri, 8 May 2020 11:36:54 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87E19C061A0C; Fri, 8 May 2020 08:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Y6GByYBpY6pH5k9QcdAJgxxwyoCDdXaPGt39GnAtfcU=; b=r/T2Qu4Dq2EPB6e8g5rt10rdUS xxIMdT2OcwOzQanXgb4lV4q1HK2YMY6jUhqZw4kqLXgZCPDWdZw6jUGIRcchb87UWGNEuuzBouvX4 4YS6XQKp60nPAtzrXWUhDMdzUDn2lFo59J/30GXVF9vyt86zvxErfvhDIjdhWfDQu5QTV2MczwT2x fGalI5f7Wmy57824Eoy61rqGOadOiirp9dqXejOb+NK5CiWjdMnCeU4VkmDWFCec3wc6SAXB9cpOu qVjmdlypsglLL/MZUS2SpJ5wA9C0Z291fcC9yHzmdGJanj/2UhJ/FJKsXGQ6ggPMKfRpM8NzQ3VrW aO9USAMw==; Received: from [2001:4bb8:180:9d3f:90d7:9df8:7cd:3504] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX53V-0004Cz-VR; Fri, 08 May 2020 15:36:54 +0000 From: Christoph Hellwig To: Alexander Viro Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 06/12] eventpoll: use __anon_inode_getfd Date: Fri, 8 May 2020 17:36:28 +0200 Message-Id: <20200508153634.249933-7-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508153634.249933-1-hch@lst.de> References: <20200508153634.249933-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Use __anon_inode_getfd instead of opencoding the logic using get_unused_fd_flags + anon_inode_getfile. Signed-off-by: Christoph Hellwig --- fs/eventpoll.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 8c596641a72b0..8abdb9fff611a 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -2055,23 +2055,14 @@ static int do_epoll_create(int flags) * Creates all the items needed to setup an eventpoll file. That is, * a file structure and a free file descriptor. */ - fd = get_unused_fd_flags(O_RDWR | (flags & O_CLOEXEC)); - if (fd < 0) { - error = fd; + fd = __anon_inode_getfd("[eventpoll]", &eventpoll_fops, ep, + O_RDWR | (flags & O_CLOEXEC), &file); + if (fd < 0) goto out_free_ep; - } - file = anon_inode_getfile("[eventpoll]", &eventpoll_fops, ep, - O_RDWR | (flags & O_CLOEXEC)); - if (IS_ERR(file)) { - error = PTR_ERR(file); - goto out_free_fd; - } ep->file = file; fd_install(fd, file); return fd; -out_free_fd: - put_unused_fd(fd); out_free_ep: ep_free(ep); return error; From patchwork Fri May 8 15:36:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 206941 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C432CC47257 for ; Fri, 8 May 2020 15:38:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A69A024953 for ; Fri, 8 May 2020 15:38:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="nLXivfej" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728299AbgEHPg7 (ORCPT ); Fri, 8 May 2020 11:36:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726736AbgEHPg5 (ORCPT ); Fri, 8 May 2020 11:36:57 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 697C4C061A0C; Fri, 8 May 2020 08:36:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=K2Uub0aVlfxersdFoVOaGQEKIhROd5F6Q0lYewfweLc=; b=nLXivfejQ+u34RbuaNX/WRviAP 4MWtTgrAfbomeTARHGscIxB0QNC16PC97aZYytTP+FF+q7ACvUTThUK9PVdWxAGifmTgZugVLsN4v QY1gxUI/EnmI8tEMw9oblbdgBRg6XuLSqvnYIAcnNngOpBkkT+DiC/aonb2qvEMT37abKrQx4gHFs 7Ds+24tMuJDuoDd7QTAAiDDNyL9wAWVw2hrtUwae9zOHmIFGIc2fBYTSfQC+irX8W7GgXn0m3XJtS S1m572ziEHrm1ZsNjB4+YI+dNh4qBo0ef6X8qTK/iM60a+t/A3rmc/Rt2hlF5iujEmK4Gl4sBeDFV V4ot9Jkg==; Received: from [2001:4bb8:180:9d3f:90d7:9df8:7cd:3504] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX53Y-0004E0-RB; Fri, 08 May 2020 15:36:57 +0000 From: Christoph Hellwig To: Alexander Viro Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 07/12] eventfd: use __anon_inode_getfd Date: Fri, 8 May 2020 17:36:29 +0200 Message-Id: <20200508153634.249933-8-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508153634.249933-1-hch@lst.de> References: <20200508153634.249933-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Use __anon_inode_getfd instead of opencoding the logic using get_unused_fd_flags + anon_inode_getfile. Signed-off-by: Christoph Hellwig --- fs/eventfd.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/fs/eventfd.c b/fs/eventfd.c index df466ef81dddf..9b6d5137679b2 100644 --- a/fs/eventfd.c +++ b/fs/eventfd.c @@ -423,20 +423,11 @@ static int do_eventfd(unsigned int count, int flags) ctx->count = count; ctx->flags = flags; ctx->id = ida_simple_get(&eventfd_ida, 0, 0, GFP_KERNEL); - - flags &= EFD_SHARED_FCNTL_FLAGS; - flags |= O_RDWR; - fd = get_unused_fd_flags(flags); + fd = __anon_inode_getfd("[eventfd]", &eventfd_fops, ctx, + (flags & EFD_SHARED_FCNTL_FLAGS) | O_RDWR, &file); if (fd < 0) goto err; - file = anon_inode_getfile("[eventfd]", &eventfd_fops, ctx, flags); - if (IS_ERR(file)) { - put_unused_fd(fd); - fd = PTR_ERR(file); - goto err; - } - file->f_mode |= FMODE_NOWAIT; fd_install(fd, file); return fd; From patchwork Fri May 8 15:36:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 206942 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D19A2C4724C for ; Fri, 8 May 2020 15:37:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A957A24953 for ; Fri, 8 May 2020 15:37:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="GEun4DGR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728469AbgEHPhf (ORCPT ); Fri, 8 May 2020 11:37:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728373AbgEHPhF (ORCPT ); Fri, 8 May 2020 11:37:05 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D447C061A0C; Fri, 8 May 2020 08:37:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=o2cUHvSZE2EbFXmmDO+7qFHMKjG62hLvo4GWWJeNlEI=; b=GEun4DGRcmfYQBOvAkSWSKBi8k hyxwpEVsIDW42KAYGD2IG0DBW+naURQPn+t9000Tcky8+RFVAtsEdZQX53snjhIgZGF1c63t/IYif RvEWHwHOScnhB1KsKDEJS554BZrnYNEgfwKy8iUVdPkSRAHRXakiHI2Hm9rO+gNqibOnH05EqkW4U QbC29MaYTQ8PfMqDDc+fnAEXz4DIo1+rtG6TFmnP7+0r0O5H3HP9m74GFinmTv/XezxrDk4NZk9q+ xjD/XRPYCLfIpl8OCBt3vIyiGgdyGXi2kJrYnLXrIhyv6HxtF6+9PEkeWLESGyC4ENeK7Kl9FUULM yItqzyPQ==; Received: from [2001:4bb8:180:9d3f:90d7:9df8:7cd:3504] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX53h-0004R3-4P; Fri, 08 May 2020 15:37:05 +0000 From: Christoph Hellwig To: Alexander Viro Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 10/12] drm_syncobj: use __anon_inode_getfd Date: Fri, 8 May 2020 17:36:32 +0200 Message-Id: <20200508153634.249933-11-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508153634.249933-1-hch@lst.de> References: <20200508153634.249933-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Use __anon_inode_getfd instead of opencoding the logic using get_unused_fd_flags + anon_inode_getfile. Signed-off-by: Christoph Hellwig --- drivers/gpu/drm/drm_syncobj.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index 42d46414f7679..b69a7be34e8c7 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -581,18 +581,11 @@ int drm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd) struct file *file; int fd; - fd = get_unused_fd_flags(O_CLOEXEC); + fd = __anon_inode_getfd("syncobj_file", &drm_syncobj_file_fops, + syncobj, O_CLOEXEC, &file); if (fd < 0) return fd; - file = anon_inode_getfile("syncobj_file", - &drm_syncobj_file_fops, - syncobj, 0); - if (IS_ERR(file)) { - put_unused_fd(fd); - return PTR_ERR(file); - } - drm_syncobj_get(syncobj); fd_install(fd, file); From patchwork Fri May 8 15:36:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 206943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DBF8C38A2A for ; Fri, 8 May 2020 15:37:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74C4224955 for ; Fri, 8 May 2020 15:37:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="QaziO0NS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728319AbgEHPhK (ORCPT ); Fri, 8 May 2020 11:37:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728355AbgEHPhI (ORCPT ); Fri, 8 May 2020 11:37:08 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 570CBC061A0C; Fri, 8 May 2020 08:37:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=NUGZNNRYFM0r6kvrHWtMu9/AVBHfp8IFXSz0BKnUiVc=; b=QaziO0NSeQwoBUsoW2UkQtna/5 NGR+c8JIXGOc/mERbPJ/qE6LMl1yRyZBdONWcRQxh2qN+Rk/qihtN73flB3sHOwJF72lSyQj02odD tRz1FUuNgGFRL/cQ8TnpfPM5h5Cp1GcTIBamE9zY4bwV4OvEgkOaL+zUguxEmbvpSuUMR1MxJzv8+ vEWhImZDiwF5ZZ6jdFCkj2PmwdYN4Nsf7H6j0MBRkCAKtQhrPY8M7ps9NjGjWNJmItph2EXtAXF+u 6pUJHGpwiV3rE/TKreks53fL62TXAD3rNPY8PafEfyIqPvSP+y90xG3LSslfGPcOAJa2l3FCXL0ip KwSFPwBQ==; Received: from [2001:4bb8:180:9d3f:90d7:9df8:7cd:3504] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX53j-0004SG-Pl; Fri, 08 May 2020 15:37:08 +0000 From: Christoph Hellwig To: Alexander Viro Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 11/12] gpiolib: use __anon_inode_getfd Date: Fri, 8 May 2020 17:36:33 +0200 Message-Id: <20200508153634.249933-12-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508153634.249933-1-hch@lst.de> References: <20200508153634.249933-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Use __anon_inode_getfd instead of opencoding the logic using get_unused_fd_flags + anon_inode_getfile. Signed-off-by: Christoph Hellwig --- drivers/gpio/gpiolib.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 40f2d7f69be26..cbcf47b1e6a40 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -736,21 +736,13 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) i--; lh->numdescs = handlereq.lines; - fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC); + fd = __anon_inode_getfd("gpio-linehandle", &linehandle_fileops, lh, + O_RDONLY | O_CLOEXEC, &file); if (fd < 0) { ret = fd; goto out_free_descs; } - file = anon_inode_getfile("gpio-linehandle", - &linehandle_fileops, - lh, - O_RDONLY | O_CLOEXEC); - if (IS_ERR(file)) { - ret = PTR_ERR(file); - goto out_put_unused_fd; - } - handlereq.fd = fd; if (copy_to_user(ip, &handlereq, sizeof(handlereq))) { /* @@ -769,8 +761,6 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) return 0; -out_put_unused_fd: - put_unused_fd(fd); out_free_descs: for (i = 0; i < count; i++) gpiod_free(lh->descs[i]); @@ -1110,21 +1100,13 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) if (ret) goto out_free_desc; - fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC); + fd = __anon_inode_getfd("gpio-event", &lineevent_fileops, le, + O_RDONLY | O_CLOEXEC, &file); if (fd < 0) { ret = fd; goto out_free_irq; } - file = anon_inode_getfile("gpio-event", - &lineevent_fileops, - le, - O_RDONLY | O_CLOEXEC); - if (IS_ERR(file)) { - ret = PTR_ERR(file); - goto out_put_unused_fd; - } - eventreq.fd = fd; if (copy_to_user(ip, &eventreq, sizeof(eventreq))) { /* @@ -1140,8 +1122,6 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) return 0; -out_put_unused_fd: - put_unused_fd(fd); out_free_irq: free_irq(le->irq, le); out_free_desc: