From: Roman Gushchin Subject: Re: [PATCH v2 1/3] lib/vsprintf: Avoid redundant work with 0 size Date: Mon, 31 Jan 2022 10:17:25 -0800 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" Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=date : from : to : cc : subject : message-id : references : content-type : in-reply-to : mime-version; s=facebook; bh=ZrYiXgnptUhnsLXIpD13wD4hr7rlD5xARxXqkd6ZTt4=; b=Dfx90OmDFZg7iNs3FUE/+4SnC1qhW8fgDq3W/ro4WDl0npLrXlmELybOe08EV21sc8gF cbD1mgSghaw3uByL0WPet0zkBLkurFiXTulZc9WTcOroslJ8BgqoPVW3+pDtajXHzwkh yHFNei/ScDa9e3nSWSCa8aFL5UmLF8D84ns= Content-Disposition: inline In-Reply-To: <20220129205315.478628-2-longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> List-ID: 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 , Rafael Aquini On Sat, Jan 29, 2022 at 03:53:13PM -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. > > Signed-off-by: Waiman Long > --- > lib/vsprintf.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index 3b8129dd374c..a65df546fb06 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 (!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); Acked-by: Roman Gushchin Thanks!