From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike Rapoport Subject: Re: [PATCH v3 1/4] lib/vsprintf: Avoid redundant work with 0 size Date: Mon, 31 Jan 2022 22:42:43 +0200 Message-ID: References: <20220131192308.608837-1-longman@redhat.com> <20220131192308.608837-2-longman@redhat.com> Mime-Version: 1.0 Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643661778; bh=RF9Uzy656eNPo86dgtYZteEf2qMfnRVGKDWgsayxNo0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=URvBe94F0JMMty2g/M6kg26bLOxEoYKeDYSuC7kvnkiHFQb0nt3o6aO+C2ToQJymO XAxwdDkfCU2XzYUPgUduz+X9dBk8UNmCBpnHrvCqeot0ipz4t58JkPVmJ3evjNkJqj EHbM/CFvqQWyvVCUN5Q/YmioMkX6yyhyMvzGzSMlwU845x3KlgzGC8sutoRk2tBrEO gkD/WBreqxVcZGhr7Nhh+wPPMnsZlCY5XfH36Udit6NpHz06ljNqa4PYJFbGz7ltzY Cynpz3oaSPQIWv4B+Rpwcewpp6Yq+lpRDN7Qgys6DG+rIgiN/GMANpUGuVAMT49dLM kW5RDxujS5QqQ== Content-Disposition: inline In-Reply-To: <20220131192308.608837-2-longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Waiman Long Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, Ira Weiny , David Rientjes , Roman Gushchin , Rafael Aquini On Mon, Jan 31, 2022 at 02:23:05PM -0500, 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. > > Note that vsnprintf() will never return -1 to indicate an error. So > skipping the call to vsnprintf() when size is 0 will have no functional > impact at all. > > Signed-off-by: Waiman Long > Acked-by: David Rientjes > Reviewed-by: Sergey Senozhatsky > Acked-by: Roman Gushchin Acked-by: Mike Rapoport > --- > lib/vsprintf.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index 3b8129dd374c..d419154b47bb 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -2895,13 +2895,15 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) > { > int i; > > + if (unlikely(!size)) > + return 0; > + > i = vsnprintf(buf, size, fmt, args); > > if (likely(i < size)) > return i; > - if (size != 0) > - return size - 1; > - return 0; > + > + return size - 1; > } > EXPORT_SYMBOL(vscnprintf); > > -- > 2.27.0 > -- Sincerely yours, Mike.