From patchwork Fri Jan 18 14:53:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 10770549 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 E29DE91E for ; Fri, 18 Jan 2019 14:54:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D03D22A185 for ; Fri, 18 Jan 2019 14:54:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C46802A4BF; Fri, 18 Jan 2019 14:54:16 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 5EA532A29C for ; Fri, 18 Jan 2019 14:54:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727817AbfAROyP (ORCPT ); Fri, 18 Jan 2019 09:54:15 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36192 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727357AbfAROyP (ORCPT ); Fri, 18 Jan 2019 09:54:15 -0500 Received: by mail-wr1-f67.google.com with SMTP id u4so15411164wrp.3 for ; Fri, 18 Jan 2019 06:54:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GGQFPlFyeUjc3cJT0M/L8VvY3A/TbWxGEsnlidESWwA=; b=AEfEvgKH/Ft6vQji3JnAEFQZ0ehy5hIK6HKQvco/l/VwxOgsQfEXJG7y7pWGWM7ybz OA7EDsqWssYslAEBE2M1smB0WTpNEQ/9fEU3a50DF0wTNC7vJK5lK2l3ya9dBzc6R0R8 fLlqelFj7MMydJSXNO+J1mNTJoMGZ7y85zGPqttVZanbMXWA8fbhW2wOuQqiJA0cxBGx H5pb3/aC8tQN979ZSgGVu3Z6G7ntM+XrkaWdr7X1K4Y6B6k7fe6Xp1EHh44SaNKYAbGK zRJZgrTs5HyI8fAl4G0GCPkfKxeFwuJs+eR1DN2qY5l6ZJZ9ibzphWAGsw9aNVg1C3WT Y83g== 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:mime-version:content-transfer-encoding; bh=GGQFPlFyeUjc3cJT0M/L8VvY3A/TbWxGEsnlidESWwA=; b=n7U3J318cYPcfunVjybZY0/UQN2yzUHIt8gC3Uyij+WHLHb7tOVne4vzZgoXYyOuqP 1jiF/WGc3b/xCGD3Up/ggUTCJ7rPrm2EjUD14aEFHGZx9Ro+Xjf2zrLigoWGKu7kjFny 5ejIF5OgEQ67TUuDEKLEdSzuQUA/54AqzlLewMsN7ghoXkamagU7/QNvsx/b63hK6VH6 FKLAHK22JiuggxzeBstMI+5naC3oN9aq/whVPp1ZireW1izdRCkgSMlTrOhoTVZXq7sa 6b44Dt8d6lTsETGTujFYqEW0VVz3gyoJbEQMpmVMcxvAOTeWre+T9xA0GaAdlvzTLj6F ILKQ== X-Gm-Message-State: AJcUukdFAQ3wTCU0KNFXUQhsTwaouWBfd++G0qMkOzl3BK7TTf75fO9W vEaK66aJepIwYWcr7xhYoUvdRg== X-Google-Smtp-Source: ALg8bN4vSFL2RSn8EEF7EMnr1q6WDzVy8m9F2ZBSiFKZ9JPdqhobHOgMYJtYaYve1Z4ARWQP9xSyWA== X-Received: by 2002:adf:f984:: with SMTP id f4mr17049884wrr.234.1547823253424; Fri, 18 Jan 2019 06:54:13 -0800 (PST) Received: from localhost.localdomain ([154.119.55.246]) by smtp.gmail.com with ESMTPSA id l15sm67655466wrw.4.2019.01.18.06.54.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 06:54:12 -0800 (PST) From: Christian Brauner To: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk Cc: tkjos@google.com, Christian Brauner Subject: [PATCH 3/5] binderfs: rework binderfs_fill_super() Date: Fri, 18 Jan 2019 15:53:42 +0100 Message-Id: <20190118145344.11532-4-christian@brauner.io> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190118145344.11532-1-christian@brauner.io> References: <20190118145344.11532-1-christian@brauner.io> MIME-Version: 1.0 X-Patchwork-Bot: notify 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 Al pointed out that on binderfs_fill_super() error deactivate_locked_super() will call binderfs_kill_super() so all of the freeing and putting we currently do in binderfs_fill_super() is unnecessary and buggy. Let's simply return errors and let binderfs_fill_super() take care of cleaning up on error. Suggested-by: Al Viro Signed-off-by: Christian Brauner --- drivers/android/binderfs.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index 02c96b5edfa9..c0fa495ee994 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -468,8 +468,8 @@ static const struct inode_operations binderfs_dir_inode_operations = { static int binderfs_fill_super(struct super_block *sb, void *data, int silent) { + int ret; struct binderfs_info *info; - int ret = -ENOMEM; struct inode *inode = NULL; struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns; @@ -495,13 +495,14 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent) sb->s_op = &binderfs_super_ops; sb->s_time_gran = 1; - info = kzalloc(sizeof(struct binderfs_info), GFP_KERNEL); - if (!info) - goto err_without_dentry; + sb->s_fs_info = kzalloc(sizeof(struct binderfs_info), GFP_KERNEL); + if (!sb->s_fs_info) + return -ENOMEM; + info = sb->s_fs_info; ret = binderfs_parse_mount_opts(data, &info->mount_opts); if (ret) - goto err_without_dentry; + return ret; info->ipc_ns = ipc_ns; info->root_gid = make_kgid(sb->s_user_ns, 0); @@ -511,12 +512,9 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent) if (!uid_valid(info->root_uid)) info->root_uid = GLOBAL_ROOT_UID; - sb->s_fs_info = info; - - ret = -ENOMEM; inode = new_inode(sb); if (!inode) - goto err_without_dentry; + return -ENOMEM; inode->i_ino = FIRST_INODE; inode->i_fop = &simple_dir_operations; @@ -527,24 +525,9 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent) sb->s_root = d_make_root(inode); if (!sb->s_root) - goto err_without_dentry; - - ret = binderfs_binder_ctl_create(sb); - if (ret) - goto err_with_dentry; - - return 0; - -err_with_dentry: - dput(sb->s_root); - sb->s_root = NULL; - -err_without_dentry: - put_ipc_ns(ipc_ns); - iput(inode); - kfree(info); + return -ENOMEM; - return ret; + return binderfs_binder_ctl_create(sb); } static struct dentry *binderfs_mount(struct file_system_type *fs_type,