Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp688016pxb; Tue, 1 Feb 2022 08:23:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4FtukvF2ZTW0xVDY3Rd+6b+8w1AQytjcF5FPwedStqWhChjmQVvPSJVfvjB4qlXW5LWQt X-Received: by 2002:a65:6041:: with SMTP id a1mr21268731pgp.231.1643732582459; Tue, 01 Feb 2022 08:23:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643732582; cv=none; d=google.com; s=arc-20160816; b=E4F47XVPKDa1n6rj+huihQx+JYPhHvjkEdmNKuie2TZF7s9P2hKdvRhfDcOjLItg5n bR2iNJJavYNImhGNrg3GJqdf8w2uiWP7xQyoD5ICOA3gWj3U0J3uBEZIDNS7zZ10Ru4M 949AXEw/6c1KKxmRNixrpnleyVf3ITaKeQZluEnChVJdoHUTTp+vBm64rzJlseWHwtOk DMjB9I+7ue9YbybO8Le+mqctQswEqSmjtkkj+/CI/qUex85CT3GQv+OTc8UVw4ECJPAM sduJEEqlDjY4ehN+PeA/CFoIvnxTIzA5Aw6BK8d9fDH+RIXLBgcc0f+zb/1WPPc/o6u5 1B7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=HAziehOIU9Lkg4HfVomkT/YlumHGHCvYjlAWoPp5lac=; b=sOxLOg4MUOVqgacTdBCKUra3HocQJB5fatdoo+KIWeX7t606euylYza0cHgPeymoS6 tfYLBdPfMD4khAAdmb3yxZDWkewABNuCkO936J+LvAdqGsXcNHypZEc00PkWDNqp5rMa /KZvneHKtM5/fmdVKRyXT9tB72or0sIw55IwmN+amZhzFyNKxiv03ksPqNzS4mS1CJnQ 4+XT+W+9dIltkB8P9+aPZyCVX6H/6XxBj8/F7ZvVmvWIyCJjnnzKfzz9+QOg6aRaINuk Tp+I207XzR/r2E1I+o7SXva4pEHnjvWgZGzJQ6UTQDAp58MtXeEV1DgB9atKqI5+fMBM IlDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aGJGWLku; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q125si16179685pgq.311.2022.02.01.08.22.49; Tue, 01 Feb 2022 08:23:02 -0800 (PST) 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=@intel.com header.s=Intel header.b=aGJGWLku; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239998AbiAaKfx (ORCPT + 99 others); Mon, 31 Jan 2022 05:35:53 -0500 Received: from mga07.intel.com ([134.134.136.100]:54756 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239989AbiAaKfw (ORCPT ); Mon, 31 Jan 2022 05:35:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643625352; x=1675161352; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=YWtKq8OcN++bgZXQOD7vrGgwPikzV7AzgE9vpzi2/ms=; b=aGJGWLkuz93qzF0+O4SpjoeqDtCRqmNGt2OylFOJ5Jg2mFBt66wpXvp1 uR+Q+YKK614Pm+W27Y4rnJn2tvX/lVRWt3KxTyUC6dfvhVcCeTdGWsId5 u3b102124K1ij9JBNMpffk/KZJhDAA+bTRmYdxiuxBi6h93hpsajE0al5 yZLc9/AWZ4vI5yAJblynCfDPQKpMb0GxgYFAnGBbij2GMEpbRrSq9NrEg WVS198gDDp1qe+1A5PEAXG9RwP4IRzFCnaU6y5kLhYq9hhRzrq6hBbJ31 aJHWDPEQBWhu1WwfaLqXvy6rvOXCvsv/XgDz9OOR3NgI+vOsUKQDCH/oP Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10243"; a="310746496" X-IronPort-AV: E=Sophos;i="5.88,330,1635231600"; d="scan'208";a="310746496" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2022 02:35:51 -0800 X-IronPort-AV: E=Sophos;i="5.88,330,1635231600"; d="scan'208";a="582605815" Received: from smile.fi.intel.com ([10.237.72.61]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2022 02:35:48 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.95) (envelope-from ) id 1nEU1E-00GpVR-3q; Mon, 31 Jan 2022 12:34:44 +0200 Date: Mon, 31 Jan 2022 12:34:43 +0200 From: Andy Shevchenko To: David Rientjes Cc: Waiman Long , Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Rasmus Villemoes , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Ira Weiny , Rafael Aquini Subject: Re: [PATCH v2 1/3] lib/vsprintf: Avoid redundant work with 0 size Message-ID: References: <20220129205315.478628-1-longman@redhat.com> <20220129205315.478628-2-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 31, 2022 at 12:30:33PM +0200, Andy Shevchenko wrote: > On Mon, Jan 31, 2022 at 12:25:09PM +0200, Andy Shevchenko wrote: > > On Sun, Jan 30, 2022 at 12:49:37PM -0800, David Rientjes wrote: > > > On Sat, 29 Jan 2022, Waiman Long wrote: > > > > > > > For *scnprintf(), vsnprintf() is always called even if the input size is > > > > 0. That is a waste of time, so just return 0 in this case. > > > > Why do you think it's not legit? > > I have to elaborate. > > For *nprintf() the size=0 is quite useful to have. > For *cnprintf() the size=0 makes less sense, but, if we read `man snprintf()`: > > The functions snprintf() and vsnprintf() do not write more than size bytes > (including the terminating null byte ('\0')). If the output was truncated due > to this limit, then the return value is the number of characters (excluding > the terminating null byte) which would have been written to the final string > if enough space had been available. Thus, a return value of size or more > means that the output was truncated. (See also below under NOTES.) > > If an output error is encountered, a negative value is returned. > > Note the last sentence there. You need to answer to it in the commit message > why your change is okay and it will show that you thought through all possible > scenarios. Also it seems currently the kernel documentation is not aligned with the code "If @size is == 0 the function returns 0." It should mention the (theoretical?) possibility of getting negative value, if vsnprintf() returns negative value. -- With Best Regards, Andy Shevchenko