From patchwork Sat Jan 29 20:53:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 12729637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F651C433EF for ; Sat, 29 Jan 2022 20:53:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A6A06B007B; Sat, 29 Jan 2022 15:53:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7090B6B007D; Sat, 29 Jan 2022 15:53:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E8B06B007E; Sat, 29 Jan 2022 15:53:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0151.hostedemail.com [216.40.44.151]) by kanga.kvack.org (Postfix) with ESMTP id 312396B007B for ; Sat, 29 Jan 2022 15:53:53 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id CC08280FFEEF for ; Sat, 29 Jan 2022 20:53:52 +0000 (UTC) X-FDA: 79084526304.18.318DA0A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 5518940002 for ; Sat, 29 Jan 2022 20:53:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643489631; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nX58UmfyCZKrrdzehrq1UxMQowz9BiWVJRz/V9rRqyY=; b=OTyzXJq5aw/I+PxhklijLlH465QQaxedwncC5Fov+hB2t8PT3rnjo4vJD7FIeo40LUSnwa NxAEgr4b01WtG+6hpRIBfvYat2dvLGie2UmAMojR3WJLcVGok006bbf+jIUpuGFrVFm9sl i3BefYgqimNa5hVcOFNZJU+s7O3qx1k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-511-h1czgUQNPdOvrroX67Un8A-1; Sat, 29 Jan 2022 15:53:48 -0500 X-MC-Unique: h1czgUQNPdOvrroX67Un8A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0772983DD21; Sat, 29 Jan 2022 20:53:46 +0000 (UTC) Received: from llong.com (unknown [10.22.16.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05BDA5DF2E; Sat, 29 Jan 2022 20:53:43 +0000 (UTC) From: Waiman Long To: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Ira Weiny , Rafael Aquini , Waiman Long Subject: [PATCH v2 1/3] lib/vsprintf: Avoid redundant work with 0 size Date: Sat, 29 Jan 2022 15:53:13 -0500 Message-Id: <20220129205315.478628-2-longman@redhat.com> In-Reply-To: <20220129205315.478628-1-longman@redhat.com> References: <20220129205315.478628-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 5518940002 X-Stat-Signature: smz5xtn9qxgoge6g6yp9gja4h7oqpd9p Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OTyzXJq5; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf04.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=longman@redhat.com X-Rspam-User: nil X-HE-Tag: 1643489631-502284 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: Roman Gushchin --- 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);