From patchwork Tue May 29 14:41:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10436167 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 14A8360327 for ; Tue, 29 May 2018 15:17:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 048B428816 for ; Tue, 29 May 2018 15:17:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED3222883F; Tue, 29 May 2018 15:17:45 +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.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 985A228816 for ; Tue, 29 May 2018 15:17:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935433AbeE2OnI (ORCPT ); Tue, 29 May 2018 10:43:08 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36378 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935030AbeE2Ol6 (ORCPT ); Tue, 29 May 2018 10:41:58 -0400 Received: by mail-wm0-f66.google.com with SMTP id v131-v6so22111865wma.1 for ; Tue, 29 May 2018 07:41:57 -0700 (PDT) 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=SrB5PQKRAUrOo+2hzFNx8FEYpn/hqIdJB/ShOHQplxA=; b=J+U+agyKWsKpv/B2CWloWlsb1xQcYyERA1rUHpyK0T1IfQnMUbsFxfRNWKBroWjtTG Bi6VHGT9ejBnSTwnjlJnLBfvQswbpPEo8ZOYpckfFTMWlHFi5loLLCrUIWrmeCJRh7dq KCE76GEwM+zJYUdZTrnH+ucqe4FwmPIEfiGgpSbgfP6y5cfU/A+DXdWHSgIh1LBHLyAC Kr0ZEouNHG5zUyFffe3SLT++chV4IQ/4AjMCvH0qSlnuTDcNT+NqWTS9XdbvDdZzWNsz MzO3+FOwpvIpmUQpF0biplcGnZI9DSZ/x0IDtZSDI0Fe+UCjjxBYAMpRM8gxkNK6Ebtq GJ/w== X-Gm-Message-State: ALKqPwcr7W8zYU80AsLyjYbK9RKav8He9jN3yFlKto5zNMAHkcG6Mc4G bbLG18yIDwtiPBYgj3nLzwHr3A== X-Google-Smtp-Source: ADUXVKJGkat9eNCT3Ns0vYw+T/MZd2FqxNmded6qJ+kS3bu4yMJI1noSXuhPD3ilW3aRX0CbFkT75Q== X-Received: by 2002:a1c:11c3:: with SMTP id 186-v6mr13198767wmr.139.1527604917341; Tue, 29 May 2018 07:41:57 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (catv-176-63-54-97.catv.broadband.hu. [176.63.54.97]) by smtp.gmail.com with ESMTPSA id q17-v6sm12572113wmf.3.2018.05.29.07.41.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 May 2018 07:41:56 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/11] ovl: clean up copy-up error paths Date: Tue, 29 May 2018 16:41:40 +0200 Message-Id: <20180529144143.16378-9-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180529144143.16378-1-mszeredi@redhat.com> References: <20180529144143.16378-1-mszeredi@redhat.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 Signed-off-by: Miklos Szeredi --- fs/overlayfs/copy_up.c | 54 +++++++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c index 1b442c14c531..ddaddb4ce4c3 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -366,12 +366,13 @@ static int ovl_create_index(struct dentry *dentry, struct dentry *origin, return err; temp = ovl_create_temp(indexdir, OVL_CATTR(S_IFDIR | 0)); + err = PTR_ERR(temp); if (IS_ERR(temp)) - goto temp_err; + goto free_name; err = ovl_set_upper_fh(upper, temp); if (err) - goto out_cleanup; + goto out; index = lookup_one_len(name.name, indexdir, name.len); if (IS_ERR(index)) { @@ -380,23 +381,13 @@ static int ovl_create_index(struct dentry *dentry, struct dentry *origin, err = ovl_do_rename(dir, temp, dir, index, 0); dput(index); } - - if (err) - goto out_cleanup; - out: + if (err) + ovl_cleanup(dir, temp); dput(temp); +free_name: kfree(name.name); return err; - -temp_err: - err = PTR_ERR(temp); - temp = NULL; - goto out; - -out_cleanup: - ovl_cleanup(dir, temp); - goto out; } struct ovl_copy_up_ctx { @@ -476,7 +467,7 @@ static int ovl_install_temp(struct ovl_copy_up_ctx *c, struct dentry *temp, return err; } -static int ovl_get_tmpfile(struct ovl_copy_up_ctx *c, struct dentry **tempp) +static struct dentry *ovl_get_tmpfile(struct ovl_copy_up_ctx *c) { int err; struct dentry *temp; @@ -490,6 +481,7 @@ static int ovl_get_tmpfile(struct ovl_copy_up_ctx *c, struct dentry **tempp) }; err = security_inode_copy_up(c->dentry, &new_creds); + temp = ERR_PTR(err); if (err < 0) goto out; @@ -500,21 +492,13 @@ static int ovl_get_tmpfile(struct ovl_copy_up_ctx *c, struct dentry **tempp) temp = ovl_do_tmpfile(c->workdir, c->stat.mode); else temp = ovl_create_temp(c->workdir, &cattr); - if (IS_ERR(temp)) - goto temp_err; - err = 0; - *tempp = temp; out: if (new_creds) { revert_creds(old_creds); put_cred(new_creds); } - return err; - -temp_err: - err = PTR_ERR(temp); - goto out; + return temp; } static int ovl_copy_up_inode(struct ovl_copy_up_ctx *c, struct dentry *temp) @@ -564,21 +548,21 @@ static int ovl_copy_up_locked(struct ovl_copy_up_ctx *c) struct inode *udir = c->destdir->d_inode; struct inode *inode; struct dentry *newdentry = NULL; - struct dentry *temp = NULL; + struct dentry *temp; int err; - err = ovl_get_tmpfile(c, &temp); - if (err) - goto out; + temp = ovl_get_tmpfile(c); + if (IS_ERR(temp)) + return PTR_ERR(temp); err = ovl_copy_up_inode(c, temp); if (err) - goto out_cleanup; + goto out; if (S_ISDIR(c->stat.mode) && c->indexed) { err = ovl_create_index(c->dentry, c->lowerpath.dentry, temp); if (err) - goto out_cleanup; + goto out; } if (c->tmpfile) { @@ -589,7 +573,7 @@ static int ovl_copy_up_locked(struct ovl_copy_up_ctx *c) err = ovl_install_temp(c, temp, &newdentry); } if (err) - goto out_cleanup; + goto out; inode = d_inode(c->dentry); ovl_inode_update(inode, newdentry); @@ -597,13 +581,11 @@ static int ovl_copy_up_locked(struct ovl_copy_up_ctx *c) ovl_set_flag(OVL_WHITEOUTS, inode); out: + if (err && !c->tmpfile) + ovl_cleanup(d_inode(c->workdir), temp); dput(temp); return err; -out_cleanup: - if (!c->tmpfile) - ovl_cleanup(d_inode(c->workdir), temp); - goto out; } /*