Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1706111pxj; Wed, 19 May 2021 11:58:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwvYFf1YAZHLhoAI63XekHAxwoHO6CheDzvZmpXtXHtUzjVXwwCoySD6lBcnn2lY/wTOcf X-Received: by 2002:aa7:d58b:: with SMTP id r11mr516144edq.231.1621450709852; Wed, 19 May 2021 11:58:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621450709; cv=none; d=google.com; s=arc-20160816; b=mzn6+ZvZAZTHjgOt7R5M+8xK72a1tE+qOfsX0BnQXrsApsLXDPDO6eV14BpbKnmysl AXsHDN6MsN0uWIxVEvho7udLS0F2qZRaWRiN9KM50iUPiqhpJF1oeTqxRSYY8WYpjQ9V EPfBU2im/tJVQzJtpczVEV5sWDgWyfobHrrpXayKc/vKOKgyN1TxrOBOqTCrBzohhklu oCEP8y7chsB/N6JJ4L7oGB+uXsoN8dmYF9ziZ/I2TlSZLGnftBvMj8/3Xy+5ZGATJ3fk mf8ruXjvC7l5/Pw3uM1nTyIWxs8qD7zEyTMJYX5stBLC21HmKLYidxeSbhAPNuW1cd+j N/2w== 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; bh=HwXAOpjtOeuwbI60JrrggKtSGSwNCpjJEySRtWy5ZoY=; b=fXEIE5+5K0o/KKA8ksv+aN4T/V0tDUGeVbIhILro/hnLw5ISFpsnuDBXDdtl2X1x+3 wZQmpei7oqPiJYddLd0yAY5Vv00PysV12mvN71t+MoPeYvTROjAxKMnrv0dt2fcZJHkZ BO3dpMdspyzOI4H+jxHsv1xpnHgRL0Dr/wz1biyHx9xn0hJ0dWnjOucSY0R4pKSye0qh uB61weUbYZcnxLB3yumn1zd77WKZz6s10z/CZvYhP83ISzYGvetu1yjKnJzkE5Mp7YO9 YOFBfBBC1oSgMwTPIcxCpRmwJhQAQwRsk315XlzL6iXf+dallrpErL0cZXxWiwjqtkxb opoA== ARC-Authentication-Results: i=1; mx.google.com; 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 b15si3604edd.87.2021.05.19.11.58.06; Wed, 19 May 2021 11:58:29 -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; 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 S231753AbhESAwu (ORCPT + 99 others); Tue, 18 May 2021 20:52:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234689AbhESAu6 (ORCPT ); Tue, 18 May 2021 20:50:58 -0400 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C05CC06175F; Tue, 18 May 2021 17:49:39 -0700 (PDT) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94 #2 (Red Hat Linux)) id 1ljAOU-00G4Fg-3B; Wed, 19 May 2021 00:49:02 +0000 From: Al Viro To: Linus Torvalds Cc: Jia He , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , Jonathan Corbet , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , "Eric W . Biederman" , "Darrick J. Wong" , "Peter Zijlstra (Intel)" , Ira Weiny , Eric Biggers , "Ahmed S. Darwish" , "open list:DOCUMENTATION" , Linux Kernel Mailing List , linux-s390 , linux-fsdevel Subject: [PATCH 07/14] d_path: lift -ENAMETOOLONG handling into callers of prepend_path() Date: Wed, 19 May 2021 00:48:54 +0000 Message-Id: <20210519004901.3829541-7-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210519004901.3829541-1-viro@zeniv.linux.org.uk> References: <20210519004901.3829541-1-viro@zeniv.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The only negative value ever returned by prepend_path() is -ENAMETOOLONG and callers can recognize that situation (overflow) by looking at the sign of buflen. Lift that into the callers; we already have the same logics (buf if buflen is non-negative, ERR_PTR(-ENAMETOOLONG) otherwise) in several places and that'll become a new primitive several commits down the road. Make prepend_path() return 0 instead of -ENAMETOOLONG. That makes for saner calling conventions (0/1/2/3/-ENAMETOOLONG is obnoxious) and callers actually get simpler, especially once the aforementioned primitive gets added. In prepend_path() itself we switch prepending the / (in case of empty path) to use of prepend() - no need to open-code that, compiler will do the right thing. It's exactly the same logics as in __dentry_path(). Signed-off-by: Al Viro --- fs/d_path.c | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/fs/d_path.c b/fs/d_path.c index 72b8087aaf9c..327cc3744554 100644 --- a/fs/d_path.c +++ b/fs/d_path.c @@ -127,8 +127,7 @@ static int prepend_path(const struct path *path, } parent = dentry->d_parent; prefetch(parent); - error = prepend_name(&bptr, &blen, &dentry->d_name); - if (error) + if (unlikely(prepend_name(&bptr, &blen, &dentry->d_name) < 0)) break; dentry = parent; @@ -149,12 +148,9 @@ static int prepend_path(const struct path *path, } done_seqretry(&mount_lock, m_seq); - if (error >= 0 && bptr == *buffer) { - if (--blen < 0) - error = -ENAMETOOLONG; - else - *--bptr = '/'; - } + if (blen == *buflen) + prepend(&bptr, &blen, "/", 1); + *buffer = bptr; *buflen = blen; return error; @@ -181,16 +177,11 @@ char *__d_path(const struct path *path, char *buf, int buflen) { char *res = buf + buflen; - int error; prepend(&res, &buflen, "", 1); - error = prepend_path(path, root, &res, &buflen); - - if (error < 0) - return ERR_PTR(error); - if (error > 0) + if (prepend_path(path, root, &res, &buflen) > 0) return NULL; - return res; + return buflen >= 0 ? res : ERR_PTR(-ENAMETOOLONG); } char *d_absolute_path(const struct path *path, @@ -198,16 +189,11 @@ char *d_absolute_path(const struct path *path, { struct path root = {}; char *res = buf + buflen; - int error; prepend(&res, &buflen, "", 1); - error = prepend_path(path, &root, &res, &buflen); - - if (error > 1) - error = -EINVAL; - if (error < 0) - return ERR_PTR(error); - return res; + if (prepend_path(path, &root, &res, &buflen) > 1) + return ERR_PTR(-EINVAL); + return buflen >= 0 ? res : ERR_PTR(-ENAMETOOLONG); } static void get_fs_root_rcu(struct fs_struct *fs, struct path *root) @@ -240,7 +226,6 @@ char *d_path(const struct path *path, char *buf, int buflen) { char *res = buf + buflen; struct path root; - int error; /* * We have various synthetic filesystems that never get mounted. On @@ -263,12 +248,10 @@ char *d_path(const struct path *path, char *buf, int buflen) prepend(&res, &buflen, " (deleted)", 11); else prepend(&res, &buflen, "", 1); - error = prepend_path(path, &root, &res, &buflen); + prepend_path(path, &root, &res, &buflen); rcu_read_unlock(); - if (error < 0) - res = ERR_PTR(error); - return res; + return buflen >= 0 ? res : ERR_PTR(-ENAMETOOLONG); } EXPORT_SYMBOL(d_path); -- 2.11.0