Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2366265imm; Tue, 10 Jul 2018 19:26:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpccdkN9YDyg8vYucEbBkikTPLmd6N/UyIsObM5Y+eU21R+ASHWItSyrpFrhyvvT1MjvPBzC X-Received: by 2002:aa7:8118:: with SMTP id b24-v6mr1034843pfi.78.1531275960901; Tue, 10 Jul 2018 19:26:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531275960; cv=none; d=google.com; s=arc-20160816; b=dQpRd5OVBu/gN0eNPK2rv1OXbxDz8tIVrR2yJxzJ7oVt4E7vTYAcJ6/0xk5REijpRU mP+HSHDudDKs9PE4jzEuHnV7YX08CjOoThtfCjgxHRmfBHEO+L8ffyMqMfIQH5NBe5F9 VF61XQmtPof5zy0BuelFAqIOFb+3oPuWu+yaYb5w/a3tg72kkrnisBlzq1KHik1qU9jn w44qH8sPje9wJjxVxhmY+o6Y1IWluXRql4PViKP2q2f3O8G3C7Zc4zb4atWRWCHcwpvL GJbL4PFj0P6c3OHV2ecaJR4O+9nI6qBFEFMKwdtTJ7cht5yfdSoEIrVBq6ViCDbIEtLV yTcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=ce9PsfM3kBnLLdzi1YW+tWzZnkIHgBaIZkfB2/u8lVM=; b=CsE3uQndc0HRKYecoPu+n8luav5nP/OM8AkFtsB1bQhJnriYz4ERdOJUHUhR9WMmsQ CCdU7hAiEB8vy9HtIAWSkHwUgBVlvob/1QCB6cHRsfc+eLZYVOj+D3Jy53OPOLXDYOOR A0W1zW10oT2vFP1B+Kvt/52LFNJt8R0I9WQTV4i+oX/J5r8BbQSz0BTkPoLgzWyshn8L ZRc/g35bVvg4Gdv2ayVRu4ADeJhC/q0knzKA5qgvgQSlz1bCc/J7WWeqgTlKrPwJFEpm MIkBABc7Cfies9V55UJ87iz3/Tk0axtx6Fwza/LV1iB49kWiwD8NwiY1f3+onME4Ovfv YyXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a67-v6si19381766pfb.348.2018.07.10.19.25.45; Tue, 10 Jul 2018 19:26:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732792AbeGKCZq (ORCPT + 99 others); Tue, 10 Jul 2018 22:25:46 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:45658 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732364AbeGKCYG (ORCPT ); Tue, 10 Jul 2018 22:24:06 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fd4ld-0003KV-7u; Wed, 11 Jul 2018 02:22:09 +0000 From: Al Viro To: Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Miklos Szeredi Subject: [RFC][PATCH 29/42] __shmem_file_setup(): reorder allocations Date: Wed, 11 Jul 2018 03:21:53 +0100 Message-Id: <20180711022206.12571-29-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180711022206.12571-1-viro@ZenIV.linux.org.uk> References: <20180711021136.GN30522@ZenIV.linux.org.uk> <20180711022206.12571-1-viro@ZenIV.linux.org.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro grab inode and reserve memory first. Signed-off-by: Al Viro --- mm/shmem.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 2cab84403055..1146a48926bc 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3918,41 +3918,38 @@ static struct file *__shmem_file_setup(struct vfsmount *mnt, const char *name, l if (shmem_acct_size(flags, size)) return ERR_PTR(-ENOMEM); - res = ERR_PTR(-ENOMEM); + sb = mnt->mnt_sb; + inode = shmem_get_inode(sb, NULL, S_IFREG | S_IRWXUGO, 0, flags); + if (unlikely(!inode)) { + shmem_unacct_size(flags, size); + return ERR_PTR(-ENOSPC); + } + inode->i_flags |= i_flags; + inode->i_size = size; + clear_nlink(inode); /* It is unlinked */ + res = ERR_PTR(ramfs_nommu_expand_for_mapping(inode, size)); + if (IS_ERR(res)) { + iput(inode); + return res; + } + this.name = name; this.len = strlen(name); this.hash = 0; /* will go */ - sb = mnt->mnt_sb; path.mnt = mntget(mnt); path.dentry = d_alloc_pseudo(sb, &this); - if (!path.dentry) - goto put_memory; + if (!path.dentry) { + iput(inode); + return ERR_PTR(-ENOMEM); + } d_set_d_op(path.dentry, &anon_ops); - res = ERR_PTR(-ENOSPC); - inode = shmem_get_inode(sb, NULL, S_IFREG | 0777, 0, flags); - if (!inode) - goto put_memory; - - inode->i_flags |= i_flags; d_instantiate(path.dentry, inode); - inode->i_size = size; - clear_nlink(inode); /* It is unlinked */ - res = ERR_PTR(ramfs_nommu_expand_for_mapping(inode, size)); - if (IS_ERR(res)) - goto put_path; res = alloc_file(&path, FMODE_WRITE | FMODE_READ, &shmem_file_operations); if (IS_ERR(res)) - goto put_path; - - return res; - -put_memory: - shmem_unacct_size(flags, size); -put_path: - path_put(&path); + path_put(&path); return res; } -- 2.11.0