Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp157023ybj; Fri, 8 May 2020 08:39:21 -0700 (PDT) X-Google-Smtp-Source: APiQypKfqzRWBngsXoh19Y+2I/WSaviBh/rJJpELwm60aJxVMpnKx3pAeUX37b89VEUApQbjBQDA X-Received: by 2002:a17:906:1d4c:: with SMTP id o12mr2393980ejh.357.1588952361367; Fri, 08 May 2020 08:39:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588952361; cv=none; d=google.com; s=arc-20160816; b=JLGsZgLBOfwujzdpf4JBpHAEK4EcufsBv4VEhRh0DSV/8aLNP+mID6CXU3jjMbCxyX hJ1vNz96cG5g58D8ZwAwEIHEg5UH0dA1lwPGVgI2ku9T0DeZrKgLwsmNuSRPuXqjMyHo X/jSMkf/d2oHF8JtN402cG1EWjPk3MhvdRy96YffOYbNONJlUacxC4PJRrNYkfDDOmvH lDCS3OH/waXn+LDY28dAWxgAIWpnDhUb8PUH16RbTfJJ1GiQVQrBj6JY9kby+4PcHBv0 3n+MIV/1RYDnOL4WeNJmJaZpm+xfF3qdEO9xLetfBZ+yLgCBKfdYNA0rnSD/5ZYBqTLz 18QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uQupytwSEXnv3/F3EONV14yFM9iDWY0BYhUPftguMlU=; b=zDXQgIkvHoas9698pk5zICVsVXNcmvOjabTIRJvI9tB5w4GmUrNJ47pH9R6/DJd89g VgR3Z5+dCmRNQXfTzPMDY5hOz/V/sS4wDZm71nhdVYUg0+pnZ5f5EiccPKaHKM57WSiR LclaD1nOBaVPf9Lk5r+g7UouR1Bmq8nZHvXRLlUR0/wfQqq/L/QQwybBm5Wl5SCu9/lF 0mJTmT4GX9CFIL0vhWXUp4iIK6W+sB3bpwh2xePdgS6yf9foUBtNuy0aSQUORk4G6anj zMtfOUEhCAr12YWrKt070dJ8zrxFH096oEij49csLvaUM9yXVOnZ7KAHq5Sm4YZJdpek 2Uqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ECjye1lF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j9si1250190edn.415.2020.05.08.08.38.58; Fri, 08 May 2020 08:39:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ECjye1lF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726689AbgEHPhO (ORCPT + 99 others); Fri, 8 May 2020 11:37:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728418AbgEHPhL (ORCPT ); Fri, 8 May 2020 11:37:11 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F247EC061A0C; Fri, 8 May 2020 08:37:10 -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=uQupytwSEXnv3/F3EONV14yFM9iDWY0BYhUPftguMlU=; b=ECjye1lFh/oDKkHSp8s8r3/PBL bY/42wC5a85E1iHD+psjQ/gkXg7hcCE7r0N2ufr4ZnmtVS2rYT80SgF8xdIozTYFqxl0tf1Z49wkr brImDOTrRr2yXeQqkxa8oM7wZ8d1A07kuZ+YelyRE3/Ejv0WR63qqwEi7NkSPvm6JCdwbnIFIuFhh ca06xctQt3/rLg9MSgExt6X6hISxql6kbhSk4akzhzTPYah7nLCyDQJuj3qQCGYA/oqYFM9Kr5h5f gIMF4UxTD82Q2/oQLlx6fL74cfXHXgNPMz/nvaxsMY6cMkjGOAWo/Ha8ThQx5El+S/JcOa/eOm9Qh ch4YtVZw==; 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 1jX53m-0004ST-Ff; Fri, 08 May 2020 15:37:10 +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 12/12] vtpm_proxy: use __anon_inode_getfd Date: Fri, 8 May 2020 17:36:34 +0200 Message-Id: <20200508153634.249933-13-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 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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/char/tpm/tpm_vtpm_proxy.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/drivers/char/tpm/tpm_vtpm_proxy.c b/drivers/char/tpm/tpm_vtpm_proxy.c index 91c772e38bb54..4c0a31209ae5a 100644 --- a/drivers/char/tpm/tpm_vtpm_proxy.c +++ b/drivers/char/tpm/tpm_vtpm_proxy.c @@ -534,7 +534,7 @@ static struct file *vtpm_proxy_create_device( struct vtpm_proxy_new_dev *vtpm_new_dev) { struct proxy_dev *proxy_dev; - int rc, fd; + int fd; struct file *file; if (vtpm_new_dev->flags & ~VTPM_PROXY_FLAGS_ALL) @@ -546,19 +546,10 @@ static struct file *vtpm_proxy_create_device( proxy_dev->flags = vtpm_new_dev->flags; - /* setup an anonymous file for the server-side */ - fd = get_unused_fd_flags(O_RDWR); - if (fd < 0) { - rc = fd; + fd = __anon_inode_getfd("[vtpms]", &vtpm_proxy_fops, proxy_dev, O_RDWR, + &file); + if (fd < 0) goto err_delete_proxy_dev; - } - - file = anon_inode_getfile("[vtpms]", &vtpm_proxy_fops, proxy_dev, - O_RDWR); - if (IS_ERR(file)) { - rc = PTR_ERR(file); - goto err_put_unused_fd; - } /* from now on we can unwind with put_unused_fd() + fput() */ /* simulate an open() on the server side */ @@ -576,13 +567,9 @@ static struct file *vtpm_proxy_create_device( return file; -err_put_unused_fd: - put_unused_fd(fd); - err_delete_proxy_dev: vtpm_proxy_delete_proxy_dev(proxy_dev); - - return ERR_PTR(rc); + return ERR_PTR(fd); } /* -- 2.26.2