From mboxrd@z Thu Jan 1 00:00:00 1970 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 70AC5C433F5 for ; Wed, 13 Oct 2021 09:59:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DFA7861077 for ; Wed, 13 Oct 2021 09:59:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DFA7861077 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=rasmusvillemoes.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D46CF6B006C; Wed, 13 Oct 2021 05:59:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF7676B0071; Wed, 13 Oct 2021 05:59:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B97DA6B0072; Wed, 13 Oct 2021 05:59:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0074.hostedemail.com [216.40.44.74]) by kanga.kvack.org (Postfix) with ESMTP id A76106B006C for ; Wed, 13 Oct 2021 05:59:42 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5FA968249980 for ; Wed, 13 Oct 2021 09:59:42 +0000 (UTC) X-FDA: 78690967404.16.ED93393 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by imf12.hostedemail.com (Postfix) with ESMTP id 01E3D100009D for ; Wed, 13 Oct 2021 09:59:41 +0000 (UTC) Received: by mail-lf1-f44.google.com with SMTP id t9so9460012lfd.1 for ; Wed, 13 Oct 2021 02:59:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=h9u9T+LntCb2bGxHWi3yPXxCSX/dwY/c7yGIr0o5Z1Q=; b=Tx4hviyXX1vkhgsp1W4YW8xLqc+d93PT4KJ9t5Q0gxQrh12jp8qIYMM+EocyeloeME 7J95HIv5JpZasF1WkIwplO5f1dy2IhhhmY2J9cXqCdFgwRih9febGa+ah07FIQzayw7/ rx88KkCts7xmEmDz2PGpy0YlmBbRiOdwMSBDc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=h9u9T+LntCb2bGxHWi3yPXxCSX/dwY/c7yGIr0o5Z1Q=; b=2TNbIURoUmkm1XCBsxLBMuhIgE3cXem0x0ELQCMLn41aur6FPF8V6P+wyhWTOrQ4Z+ /5M5R81Fb1WK9uHd0smPMLCJdAqVwJLyWS1NY7f2R3vmguxvRcA1xQSyabPog/CPLvwJ ZZo9LzxGm/pS50CQF3hx5j7l3jBXPU5MX1SLjuvm356WqVdYbGDeIZl+AmR6y7Ivm6R2 3NGv+c+iL/NKBOzp3SnWqmQRW4e0r7fCj32qRVxEZoECYLqrf9BckzuoKbneNK+5f0N2 I2raFr8Mi55v8I+CjBDF9O9PHS8Mbfh0IWR8aUWcERXcgAOce+iKsvxI8lX5yZMzAk2R xg9g== X-Gm-Message-State: AOAM5314AzOIadA/Yk9vlod0uRn3BQoRfzovS9JC7bp3e7TUtokwp47c do8JtZ+ZL0lJGwCFHRnotMyr2A== X-Google-Smtp-Source: ABdhPJwpRRz/9gHe2e5eqFOnhIDABdbGhpoos/67fUtRpyaZT8AWxfyavP5W5le5TIQmugKNFLfIvw== X-Received: by 2002:a05:6512:1196:: with SMTP id g22mr15826173lfr.661.1634119180178; Wed, 13 Oct 2021 02:59:40 -0700 (PDT) Received: from [172.16.11.1] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id r22sm887218lfe.239.2021.10.13.02.59.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Oct 2021 02:59:39 -0700 (PDT) Subject: Re: [PATCH 4/5] test_printf: Append '|' more efficiently To: Yafang Shao , "Matthew Wilcox (Oracle)" Cc: Sergey Senozhatsky , Petr Mladek , Linux MM , Vlastimil Babka References: <20211012182647.1605095-1-willy@infradead.org> <20211012182647.1605095-5-willy@infradead.org> From: Rasmus Villemoes Message-ID: <18622fb5-c4cd-7e4c-b295-e06837261fc5@rasmusvillemoes.dk> Date: Wed, 13 Oct 2021 11:59:38 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=rasmusvillemoes.dk header.s=google header.b=Tx4hviyX; spf=pass (imf12.hostedemail.com: domain of linux@rasmusvillemoes.dk designates 209.85.167.44 as permitted sender) smtp.mailfrom=linux@rasmusvillemoes.dk; dmarc=none X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 01E3D100009D X-Stat-Signature: wo556u59nsycni9867cibprug3379rz1 X-HE-Tag: 1634119181-516197 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: On 13/10/2021 07.22, Yafang Shao wrote: > On Wed, Oct 13, 2021 at 2:33 AM Matthew Wilcox (Oracle) > wrote: >> >> Instead of calling snprintf(), just append '|' by hand. >> >> Signed-off-by: Matthew Wilcox (Oracle) >> --- >> lib/test_printf.c | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/lib/test_printf.c b/lib/test_printf.c >> index 60cdf4ba991e..662c3785aa57 100644 >> --- a/lib/test_printf.c >> +++ b/lib/test_printf.c >> @@ -623,9 +623,9 @@ 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 < BUF_SIZE) { > > Should it be: > if (append && size < BUF_SIZE - 1) > ? > Perhaps, but the whole thing screams "don't do it like this". We have seq_buf to abstract a "buffer with known length you can do a bunch of snprintfs to". That's what should be used. Then the test can also error out if seq_buf_has_overflowed(), because that's a bug in the test. Alternatively, the right pattern is "size += scnprintf(cmp_buf + size, BUF_SIZE - size)", since that will eventually saturate size at BUF_SIZE-1. Rasmus