Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp533721pxj; Fri, 28 May 2021 09:21:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAoy67bA952qlYJ39Gv6eS28spu+1hjGFW08OD8CI+spOlpi05J3rI44Te7Q5tDW97PrAB X-Received: by 2002:a5e:8c11:: with SMTP id n17mr7612911ioj.53.1622218909507; Fri, 28 May 2021 09:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622218909; cv=none; d=google.com; s=arc-20160816; b=m9CSds8A4c/9N7gPV4cTkcBbhRTXO6z3dyH5rhjA8pClMEnGI4nAsxx4Lszix6TPjn 4LtL7rjWZzRLh0DjhOitKPf8cyGA8xEj0RmuzT34kRNHxm1kjqe04gBTMqQKCJ8RXiBj YJNVpmzMSF5sAgcQWebSOBEu/EgEM2GOLI9O3UIxbQBKrC5mQkVQvpEWG5qJUy4vi9AI mjaiRQ5gEdl88BFOco9Lz5oTq2JIIwq2/BZ45GUqaWLhqbobll3Qz9iuttPCllJh5IZM eTceNNV4d7CIV28pUtNQaRQTQwp1UyDIsCPqXz+a/g52TTp/wG37zvcTc6T9jtGmc1WB zV6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UM5DN4/cqvUU0xmTLWTsMkmBxsLpKI9DFsTdLupUfM8=; b=fOYVLATMH3pES7CXrbGkNw/+5UlPSzqjAxLQ8X/6lhiGoHXdvnDs7EUi7AyQrdT5Al EiqzFJwzw4u2jiOnp9LgHuYScL8iX4Vwf1w7GAsyMpZqFG3PQkQgWLacSSyp8qQFb5jj CpAbGExzJoRt+I9VE/6VzKFqSx8keJPfvQLeEObAwTLKdzM8Dyspyf+17Xa3Kew0fuEF ptpxWaWlVS01147HAT+990tAgJGo6UuEbd+PU+u4OtRyVB8zUf5sHOCitobREhrSUcAo cYNTyPev/k/q+sYx/sXwdX2rw7h3B7QLRXQD65zDV3U6LKQjni6nVMc9hrju0rdXgGQj 2Cpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=rixJj00v; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-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 r17si5462912ilq.4.2021.05.28.09.21.34; Fri, 28 May 2021 09:21:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=rixJj00v; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236285AbhE1PYu (ORCPT + 99 others); Fri, 28 May 2021 11:24:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229684AbhE1PYk (ORCPT ); Fri, 28 May 2021 11:24:40 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52AEAC061574; Fri, 28 May 2021 08:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=UM5DN4/cqvUU0xmTLWTsMkmBxsLpKI9DFsTdLupUfM8=; b=rixJj00vbxOG8VpsVpP8RbwTCr 7BdeaCq+hpyarwuXl+O3dOf5/mfbsr/do79SCZlf3on6u8YY3NZmQbi6VKZ8WEVqtJtGGU/Q0QI7E 7/13hGYvF6K3ei013bzRtVwFVdSGdx+hMe5efukKz3ZVKnOnRqw5ipIDrdLxIBXF6zNNSS2CYn64r jkpPmGKmoUPksIDohqJaF0jo59P0Pfx82bIhjUY9UQECizoXUfdRMsXEPSo3rHMhIEkG02qytSW0/ l9fmshRAtie23VjM/0TiggGalzRIWEC+vtQb/ObqtL/vKtzI+k3STDAathHQRnqwoIrkw7vZ+dFfN VUIRZJ2Q==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lmeJU-006kN3-P6; Fri, 28 May 2021 15:22:20 +0000 Date: Fri, 28 May 2021 16:22:16 +0100 From: Matthew Wilcox To: Justin He Cc: Linus Torvalds , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , Jonathan Corbet , Alexander Viro , Luca Coelho , Kalle Valo , "David S. Miller" , Jakub Kicinski , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Johannes Berg , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-wireless@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-s390@vger.kernel.org" Subject: Re: [PATCH RFCv2 2/3] lib/vsprintf.c: make %pD print full path for file Message-ID: References: <20210528113951.6225-1-justin.he@arm.com> <20210528113951.6225-3-justin.he@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Fri, May 28, 2021 at 03:09:28PM +0000, Justin He wrote: > > I'm not sure why it's so complicated. p->len records how many bytes > > are needed for the entire path; can't you just return -p->len ? > > prepend_name() will return at the beginning if p->len is <0 in this case, > we can't even get the correct full path size if keep __prepend_path unchanged. > We need another new helper __prepend_path_size() to get the full path size > regardless of the negative value p->len. It's a little hard to follow, based on just the patches. Is there a git tree somewhere of Al's patches that you're based on? Seems to me that prepend_name() is just fine because it updates p->len before returning false: static bool prepend_name(struct prepend_buffer *p, const struct qstr *name) { const char *dname = smp_load_acquire(&name->name); /* ^^^ */ u32 dlen = READ_ONCE(name->len); char *s; p->len -= dlen + 1; if (unlikely(p->len < 0)) return false; I think the only change you'd need to make for vsnprintf() is in prepend_path(): - if (!prepend_name(&b, &dentry->d_name)) - break; + prepend_name(&b, &dentry->d_name); Would that hurt anything else? > More than that, even the 1st vsnprintf could have _end_ > _buf_ in some case: > What if printk("%pD", filp) ? The 1st vsnprintf has positive (end-buf). I don't understand the problem ... if p->len is positive, then you succeeded. if p->len is negative then -p->len is the expected return value from vsnprintf(). No?