Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3428072pxj; Tue, 15 Jun 2021 00:15:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzF+gqd6W6aRUgol7anAGBrn0/gV0jpMnpBFtNKQfK463LTFyLZvEHtLcH1ExLk31AI2vok X-Received: by 2002:a05:6602:2001:: with SMTP id y1mr17334249iod.181.1623741327125; Tue, 15 Jun 2021 00:15:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623741327; cv=none; d=google.com; s=arc-20160816; b=vZs7dxjc7spbty6H2w3KqSXLoTztjlo9TZ0UOTg2vp/QXdI5feII0EHuwwMyrCwLmW pO7DL/DmXFH6bW5hxRIU6YfwNB/UG7udZ0MitFWIYbmsV+6Dx0ObWEBiDX4PeSuREWBF P9HvJovZUaXngrNCOGSp4LMHE60r4JVGDWMfQwdRwtpGXiKrSggs2KJndCp0wITu/nxU h1YQcRrH52TOilt2a6dBUo4J60kUc5Pglj+NkDS1qZOy+p6MEaptEQB9P12Ns16Fa08/ 9lvrk2/1wWBpWkgsXgeO1o0X9hCt1LO9tc3rPsf9ggTqzci439nkDDyqcOk/i6Eavov/ yS/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=euuI3sy0vUASeXoR3VF/cB0ofsJ2xtWE3m2SATxLwmE=; b=fmaZXQU9BmnMAMKl4thhmIuvWcgL7TjLHMjOSXRfjFR9ncssehivYa/4whUYiZWQ7a ma8cYwP5V2cd8VOW97YwM8NvpHz25Pq9WQVxhfJIA5WX3eVElYr9xEV5t6uWP7BH8ib+ QGBKyl9oRwxl5YCrG/m/MqH4ImrqliaPb1/UMkelB6ZsHkkTU0LyoK0V8rL3TU79MShz n8S5ru3egW6uSh4Zoui5Oir6avsbBbhMnRQVoAxFZFvPb/vZfeqKvJWLPPpKLoHgSZe4 gvn+iuM4KLRb7g+/djeAW+Zdn48FDFO0ZaMTgkkGV6MwBG32NbOFMQyo4tp39zStq/3L p1zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=AomJNf88; 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 r21si19438491jai.29.2021.06.15.00.15.14; Tue, 15 Jun 2021 00:15:27 -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; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=AomJNf88; 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 S229494AbhFOHQr (ORCPT + 99 others); Tue, 15 Jun 2021 03:16:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229493AbhFOHQp (ORCPT ); Tue, 15 Jun 2021 03:16:45 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3290C061767 for ; Tue, 15 Jun 2021 00:14:39 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id gt18so2302433ejc.11 for ; Tue, 15 Jun 2021 00:14:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=euuI3sy0vUASeXoR3VF/cB0ofsJ2xtWE3m2SATxLwmE=; b=AomJNf88QS9O+s+qQw3D2dxQMVlYRACJ3W6XV/Qfc9QG0D0RMI5MlxK9IjvvJIfClI 5zXWKP6nSPEoagEG9oFTv/mhIC7PoaOzqpANzJ5ugqNtCLdKU6Jlc9TgwIf0qa3UIqnp YEc2nN5Za8ELHgcu0qqnD0SgUiv8OTTTmTsiY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=euuI3sy0vUASeXoR3VF/cB0ofsJ2xtWE3m2SATxLwmE=; b=RkndxXsa6zD1lMhC4XZ6E8lIj7sKNY8u/bA6AzitLgB9hC/bbKqIOHBbR86QiEtMoG Mj6pbHHxjHuCLhXjp4BPNjIDn6168Uk1unUg7J6g+xyuIC+Bj22Wfh4SRgwkW5tTDqC1 7OgntIh/3DSJuG3KYSmSi36SRXCLilrt7cEMB0eJm8NTatrOsv6VHInApFrnu+KolcI4 gCrUnoSeegnhRTKybFNKU/IBwE2L+Zs+0k5gHkUd9lRGNfUa+aZNdyybl7vq2J3qReBC mjaN1tx/ojNUKPq/rxtaWRZ981VIiYrcquUk2hK/e5oNfD5hWrrmHU4RLTFkV2RsyDPD qSVA== X-Gm-Message-State: AOAM531yA5LXbzCJHEzXnPQ5WFbeXOOpzdZM0kbvh85bY3KiLBxE87jA rP3jgBJUNakJP++f8MXEYRLgOA== X-Received: by 2002:a17:906:25db:: with SMTP id n27mr18868513ejb.170.1623741278609; Tue, 15 Jun 2021 00:14:38 -0700 (PDT) Received: from [192.168.1.149] ([80.208.64.110]) by smtp.gmail.com with ESMTPSA id br21sm9160791ejb.124.2021.06.15.00.14.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Jun 2021 00:14:38 -0700 (PDT) Subject: Re: [PATCH RFCv3 2/3] lib/vsprintf.c: make %pD print full path for file To: Justin He , Petr Mladek Cc: Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , Jonathan Corbet , Alexander Viro , Linus Torvalds , "Peter Zijlstra (Intel)" , Eric Biggers , "Ahmed S. Darwish" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" References: <20210611155953.3010-1-justin.he@arm.com> <20210611155953.3010-3-justin.he@arm.com> From: Rasmus Villemoes Message-ID: <113d9380-8493-1bde-9c76-992f4ce675d9@rasmusvillemoes.dk> Date: Tue, 15 Jun 2021 09:14:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15/06/2021 08.48, Justin He wrote: > Hi Petr > >>> + /* no filling space at all */ >>> + if (buf >= end || !buf) >>> + return buf + reserved_size; >>> + >>> + /* small space for long name */ >>> + if (buf < end && prepend_len < 0) >>> + return string_truncate(buf, end, p, dpath_len, spec); >> >> We need this only because we allowed to write the path behind >> spec.field_width. Do I get it right? > > Both of field_width and precision: > "%.14pD" or "%8.14pD" Precision is never gonna be used with %p (or any of its kernel extensions) because gcc would tell you foo.c:5:13: warning: precision used with ?%p? gnu_printf format [-Wformat=] 5 | printf("%.5p\n", foo); and there's no way -Wformat is going to be turned off to allow that usage. IOW, there's no need to add complexity to make "%.3pD" of something that would normally print "/foo/bar" merely print "/fo", similar to what a precision with %s would mean. As for field width, I don't know if it's worth honouring, but IIRC the original %pd and %pD did that (that's where we have widen_string etc. from). Other %p extensions put the field with to some other use (e.g. the bitmap and hex string printing), so they obviously cannot simultaneously use it in the traditional sense. Rasmus