Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2365026imm; Tue, 10 Jul 2018 19:23:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdAwoj0K0L5indVpXRCiMkPeJyZMEkVFiN/B7Bvn/jou9qgyAH3OQ4ER9OD6ZgGTLdWUosb X-Received: by 2002:a63:5624:: with SMTP id k36-v6mr24858118pgb.146.1531275836628; Tue, 10 Jul 2018 19:23:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531275836; cv=none; d=google.com; s=arc-20160816; b=RHbu/L91Ileb/0NnANPjg4LzSUKGDHdUwdHtJiiPz8FN+IQkK0GhRXMA5W7hJZyAuE higqQZkJT2qXJCDL1rwuRcNigHWe2268o4fKW33DVBFFQE6tc58a5mtk1C7xjeJ1eMeg ypQrMNVBSc6hF1FpSuT2olPcsThGfRc47oWxtN4oQ4PL5alq1Iuk9VqpYI31Nj1sjd4r INmUBewY93e1kP92ry7BRIQgyKW9fMKoUCnXsUgwgQFblAbgPV7l9GuAKdpiKRjsLLsW GTnn5R8HXhLm15P5XtE9GYi0ITusTFSSqqpnOQRkITqvyDev7z0XYOsurRcT1CmjG8Ea kNew== 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=qljpy7KhUg9C4INoNV8MVz+8UFgFG5DBURJZ4D6IBWE=; b=lhRVl0CeWRlVMBhr6C7m7nDP/z6txbW9U1QTPavWirueEe6+68eg6jFiny50pE6Han Ws2pKaUg9GSt1Urnspk1D/LNuIksWUIl62EbzKZ8diqIRCGkX1HGDSuX7PYQrB/wju6J Q/+FWn6tp7q8AMHgYMLi8x7tVZqmrofDGqjjJC9KEbgcXSeKiYSmGFgyJJJm3j/Vk5pt IWArVqGNDWBI5pGogYnAILT+PvRJtVFgp1OFka6+SestIZ5NCViFgygwvacf8GAXBJEN C92ueHIyUTtWLil3h+0yr++6vlHETYHJVqcAibE5ysfgoHIYnElffW2KE9XaWBzoL+9K OA4w== 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 97-v6si17942762plm.444.2018.07.10.19.23.41; Tue, 10 Jul 2018 19:23:56 -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 S1732720AbeGKCYh (ORCPT + 99 others); Tue, 10 Jul 2018 22:24:37 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:45732 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732601AbeGKCYI (ORCPT ); Tue, 10 Jul 2018 22:24:08 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fd4lf-0003M4-NZ; Wed, 11 Jul 2018 02:22:11 +0000 From: Al Viro To: Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Miklos Szeredi Subject: [RFC][PATCH 41/42] allow link_path_walk() to take ERR_PTR() Date: Wed, 11 Jul 2018 03:22:05 +0100 Message-Id: <20180711022206.12571-41-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 There is a check for IS_ERR(name) immediately upstream of each call of link_path_walk(name, nd), with positives treated as if link_path_walk() failed with PTR_ERR(name). Taking that check into link_path_walk() itself simplifies things nicely. Signed-off-by: Al Viro --- fs/namei.c | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index a9a2a8ac8b9d..a55da43f169c 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2028,6 +2028,8 @@ static int link_path_walk(const char *name, struct nameidata *nd) { int err; + if (IS_ERR(name)) + return PTR_ERR(name); while (*name=='/') name++; if (!*name) @@ -2265,12 +2267,7 @@ static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path const char *s = path_init(nd, flags); int err; - if (IS_ERR(s)) { - terminate_walk(nd); - return PTR_ERR(s); - } - - if (unlikely(flags & LOOKUP_DOWN)) { + if (unlikely(flags & LOOKUP_DOWN) && !IS_ERR(s)) { err = handle_lookup_down(nd); if (unlikely(err < 0)) { terminate_walk(nd); @@ -2281,10 +2278,6 @@ static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path while (!(err = link_path_walk(s, nd)) && ((err = lookup_last(nd)) > 0)) { s = trailing_symlink(nd); - if (IS_ERR(s)) { - err = PTR_ERR(s); - break; - } } if (!err) err = complete_walk(nd); @@ -2331,12 +2324,7 @@ static int path_parentat(struct nameidata *nd, unsigned flags, struct path *parent) { const char *s = path_init(nd, flags); - int err; - if (IS_ERR(s)) { - terminate_walk(nd); - return PTR_ERR(s); - } - err = link_path_walk(s, nd); + int err = link_path_walk(s, nd); if (!err) err = complete_walk(nd); if (!err) { @@ -2663,17 +2651,10 @@ path_mountpoint(struct nameidata *nd, unsigned flags, struct path *path) { const char *s = path_init(nd, flags); int err; - if (IS_ERR(s)) { - terminate_walk(nd); - return PTR_ERR(s); - } + while (!(err = link_path_walk(s, nd)) && (err = mountpoint_last(nd)) > 0) { s = trailing_symlink(nd); - if (IS_ERR(s)) { - err = PTR_ERR(s); - break; - } } if (!err) { *path = nd->path; @@ -3512,19 +3493,10 @@ static struct file *path_openat(struct nameidata *nd, } s = path_init(nd, flags); - if (IS_ERR(s)) { - terminate_walk(nd); - fput(file); - return ERR_CAST(s); - } while (!(error = link_path_walk(s, nd)) && (error = do_last(nd, file, op)) > 0) { nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL); s = trailing_symlink(nd); - if (IS_ERR(s)) { - error = PTR_ERR(s); - break; - } } terminate_walk(nd); out2: -- 2.11.0