From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sergey Senozhatsky Subject: Re: [PATCH v2 1/3] lib/vsprintf: Avoid redundant work with 0 size Date: Mon, 31 Jan 2022 11:53:40 +0900 Message-ID: References: <20220129205315.478628-1-longman@redhat.com> <20220129205315.478628-2-longman@redhat.com> Mime-Version: 1.0 Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6nez3pOZHeNZeiNmWCxSv7m+o4l1wZUkGv8l3sBghcI=; b=bl5s49Mf5Jo0PPhp/YsG2pTfX/cSkte5Lb2YhdUnfcNtzIDFxkyo9yob+m2iPtZt5l xv1Vy09vmGfTJgQMgshwZY6wjI8DTo9tDQAicdQ1O3Aqys0vTHUn6jxnEoqVLuU2iR4W zrtwNdfbEMlcxfBvB1g967RSxbAm1PeIBDoKQ= Content-Disposition: inline In-Reply-To: <20220129205315.478628-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 , Rafael Aquini On (22/01/29 15:53), 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 Reviewed-by: Sergey Senozhatsky > +++ 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);