From patchwork Tue Oct 19 14:26:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 12570085 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 500E6C433EF for ; Tue, 19 Oct 2021 14:33:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 966476115A for ; Tue, 19 Oct 2021 14:33:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 966476115A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 3394A6B006C; Tue, 19 Oct 2021 10:33:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E8DC6B0071; Tue, 19 Oct 2021 10:33:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D799900002; Tue, 19 Oct 2021 10:33:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id 0D83B6B006C for ; Tue, 19 Oct 2021 10:33:47 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id BC348181CC1C2 for ; Tue, 19 Oct 2021 14:33:46 +0000 (UTC) X-FDA: 78713430852.24.901881B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf08.hostedemail.com (Postfix) with ESMTP id F37C930000B1 for ; Tue, 19 Oct 2021 14:33:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=bauy/NBIkxCTiWPPxOuFHCX4UJjkp/ChiiCjTaqvSSU=; b=NH3FDQNy+psWnsc7e1NqaW0lQY +dox/UFnAjZorRh1IC/Jtp9Cf0Pedu8dLCpFcsASSJ4bxdzI236JDcUo38cBdsu0Qgx+4Igf+yVCO FzowYM4G4A/hYSwraliGvFV7TpcnQqXf2ZifvkwZE2D+RnPngHnxz+OvqMiD0z0E3b4bPYh/OO50Q YW8WvVnr8ICLcdPCBR6XCAkNJQepb+kdeimQpvY6aY9ZZIh2fzAMcI7DzTTZPObvjDRb30VrVtoMu gubCnlqIQuBuFvT8ExPMnL72Gl3ReOYmfEAzT7Kfr7c/kp+rcqFdqiyqvzq3WYCpBxjYYSo6EiU6N KOpddm+A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcq8K-00BnAb-1b; Tue, 19 Oct 2021 14:31:03 +0000 From: "Matthew Wilcox (Oracle)" To: Yafang Shao Cc: "Matthew Wilcox (Oracle)" , Sergey Senozhatsky , Petr Mladek , linux-mm@kvack.org, Vlastimil Babka , Rasmus Villemoes Subject: [PATCH v2 4/5] test_printf: Append strings more efficiently Date: Tue, 19 Oct 2021 15:26:20 +0100 Message-Id: <20211019142621.2810043-5-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211019142621.2810043-1-willy@infradead.org> References: <20211019142621.2810043-1-willy@infradead.org> MIME-Version: 1.0 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=NH3FDQNy; dmarc=none; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: F37C930000B1 X-Stat-Signature: j3nhcirpwi4zydaqouisu8y4gwpzeuar X-HE-Tag: 1634654021-632219 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: Use scnprintf instead of snprintf + strlen. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Yafang Shao Reviewed-by: Petr Mladek --- lib/test_printf.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/test_printf.c b/lib/test_printf.c index ec584196cb99..d09993fca463 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -614,8 +614,7 @@ page_flags_test(int section, int node, int zone, int last_cpupid, int i; if (flags & PAGEFLAGS_MASK) { - snprintf(cmp_buf + size, BUF_SIZE - size, "%s", name); - size = strlen(cmp_buf); + size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s", name); append = true; } @@ -623,17 +622,14 @@ page_flags_test(int section, int node, int zone, int last_cpupid, if (!pft[i].width) continue; - if (append) { - snprintf(cmp_buf + size, BUF_SIZE - size, "|"); - size = strlen(cmp_buf); - } + if (append) + size += scnprintf(cmp_buf + size, BUF_SIZE - size, "|"); flags |= (values[i] & pft[i].mask) << pft[i].shift; - snprintf(cmp_buf + size, BUF_SIZE - size, "%s=", pft[i].name); - size = strlen(cmp_buf); - snprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt, - values[i] & pft[i].mask); - size = strlen(cmp_buf); + size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s=", + pft[i].name); + size += scnprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt, + values[i] & pft[i].mask); append = true; }