Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3656114pxj; Tue, 1 Jun 2021 10:06:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy445DcNHP/7dmzVO5Yfyn3vo0m06ER0X2agq7oe6DGGl9oRnPGWuYQvQzUBbL7qyForTUG X-Received: by 2002:a05:6e02:11a8:: with SMTP id 8mr23939377ilj.212.1622567210599; Tue, 01 Jun 2021 10:06:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622567210; cv=none; d=google.com; s=arc-20160816; b=lBQ0J47tuMCHWVDZqFciBuTK+BUmMq+KPGmOdewOSfHac0RSMhrJeSxMycI6/nwYkf IAzjZt63eNyc3A8wVmIWSndrx7Zo/JpShKDFBEVwD1s8tTrEG4KB6uwWYSWqmVV1oXgy le2pmmgpanvZKQz7JSGTVrMTUPro/qTCTgubdWBn8XIwQn+8udOdBaoxXVViZXEO5Jnq EndWNYiU9y8bqq4f9JY3/OjccqDH266OsG+11XmjktxfZ7lwz1AUKezqH0uU7dPIsCAt aLftX7uJTJAns98cQCGtVbUoKVscHXCrDYyy6r/zh0n117yErc3FPbZUWjiDl41y+17w eD8A== 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=hA62la00vFMppd9s1AomcqtrMlyNDRJAkQFp1nXnFAg=; b=yTmy6pPSvuVWKhScEmWsqXn1g1GWTcU/rR+Syon5/IDCj/LlVZ5wu+v5aUUiLi3dh8 7u9TzuTAo4KQaWjhPuDDcnX6HjvBZPp7cx+gvtB2XCAF4KiQuNpixlT6nb6iAMFlBYsO MWkiAsAJq4e4rJoCrb88cEGVmqS3u8YkQncezRILlhQaRI+KVFWVq2K0U5203Sr7Aywa gBXoeNcPigtEvBB/tWGBxu2gZiHKaCGkMQso2romlENKkbozLlDbnqYt1NCrx/B+Bz8S Kkhj7ARTvtckWwOeU0v86TLTUiVXrY5THPfAt+EtNxsTNsHBnJhg5M+MpmIL9Dlb+9eg Ixuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=bhrq8HGv; 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 y7si4429865ilv.7.2021.06.01.10.06.33; Tue, 01 Jun 2021 10:06:50 -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=bhrq8HGv; 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 S234440AbhFARIE (ORCPT + 99 others); Tue, 1 Jun 2021 13:08:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231918AbhFARIE (ORCPT ); Tue, 1 Jun 2021 13:08:04 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C0B5C061574; Tue, 1 Jun 2021 10:06:22 -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=hA62la00vFMppd9s1AomcqtrMlyNDRJAkQFp1nXnFAg=; b=bhrq8HGvk2ZC9QEwuF3N+FtO15 D91cwCGObxRWpjhgo3KsDyZ/ccqpaKL1PKiqNJ6DyXoAd3sH8j3/v38LCVcvBBaQBBbuic3LwsDAJ +8tAvC6xnAzAmA2HBRfvUbPq/pfObzWigW5VlFNHN6lhA+Gd/VRL+a5EXewYUpnCrHRxvkb1TzGlH N401VSuO7kjeKd04aOalX52/LMQFAWweJvJvB+wz/rFUfpsnLI/iY+MRzMxnPT/d5GwzdRe7k/JbE vf5bEBx1jR7MUlL5Kj0nk0aza5v71zysqRMPjrRoDA00lec1DdVTRanpocwFGdS/z1Iad8J2I7IBt rFdK0zyg==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lo7pK-00AEY3-91; Tue, 01 Jun 2021 17:05:15 +0000 Date: Tue, 1 Jun 2021 18:05:14 +0100 From: Matthew Wilcox To: Andy Shevchenko Cc: Justin He , Linus Torvalds , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , 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" , Linux FS Devel Subject: Re: [PATCH RFCv2 2/3] lib/vsprintf.c: make %pD print full path for file Message-ID: References: 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 Tue, Jun 01, 2021 at 07:10:41PM +0300, Andy Shevchenko wrote: > On Tue, Jun 01, 2021 at 06:53:26PM +0300, Andy Shevchenko wrote: > > On Tue, Jun 01, 2021 at 04:44:00PM +0100, Matthew Wilcox wrote: > > > On Tue, Jun 01, 2021 at 06:36:41PM +0300, Andy Shevchenko wrote: > > > > On Tue, Jun 1, 2021 at 6:32 PM Matthew Wilcox wrote: > > > > > On Tue, Jun 01, 2021 at 02:42:15PM +0000, Justin He wrote: > > > > > > > > ... > > > > > > > > > Just don't put anything > > > > > in the buffer if the user didn't supply enough space. As long as you > > > > > get the return value right, they know the string is bad (or they don't > > > > > care if the string is bad) > > > > > > > > It might be that I'm out of context here, but printf() functionality > > > > in the kernel (vsprintf() if being precise) and its users consider > > > > that it should fill buffer up to the end of whatever space is > > > > available. > > > > > > Do they though? What use is it to specify a small buffer, print a > > > large filename into it and then use that buffer, knowing that it wasn't > > > big enough? That would help decide whether we should print the > > > start or the end of the filename. > > > > > > Remember, we're going for usefulness here, not abiding by the letter of > > > the standard under all circumstances, no matter the cost. At least > > > partially because we're far outside the standard here; POSIX does > > > not specify what %pD does. > > > > > > "The argument shall be a pointer to void. The value of the > > > pointer is converted to a sequence of printable characters, in an > > > implementation-defined manner." > > > > All nice words, but don't forget kasprintf() or other usages like this. > > For the same input we have to have the same result independently on the room in > > the buffer. > > > > So, if I print "Hello, World" I should always get it, not "Monkey's Paw". > > I.o.w. > > > > snprintf(10) ==> "Hello, Wor" > > snprintf(5) ==> "Hello" > > snprintf(2) !=> "Mo" > > snprintf(1) !=> "M" > > snprintf(1) ==> "H" > > > > Inconsistency here is really not what we want. > > I have to add that in light of the topic those characters should be counted > from the end of the filename. So, we will give user as much as possible of useful > information. I.o.w. always print the last part of filename up to the buffer > size or if the filename is shorter than buffer we will have it in full. Ah, not monkey's paw, but donkey hoof then ... Here's some examples, what do you think makes sense? snprintf(buf, 16, "bad file '%pD'\n", q); what content do you want buf to have when q is variously: 1. /abcd/efgh 2. /a/bcdefgh.iso 3. /abcdef/gh I would argue that "bad file ''\n" is actually a better string to have than any of (case 2) "bad file '/a/bc" "bad file 'bcdef" "bad file 'h.iso"