From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Yafang Shao <laoar.shao@gmail.com>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Petr Mladek <pmladek@suse.com>, Linux MM <linux-mm@kvack.org>,
Vlastimil Babka <vbabka@suse.cz>
Subject: Re: [PATCH 4/5] test_printf: Append '|' more efficiently
Date: Wed, 13 Oct 2021 11:59:38 +0200 [thread overview]
Message-ID: <18622fb5-c4cd-7e4c-b295-e06837261fc5@rasmusvillemoes.dk> (raw)
In-Reply-To: <CALOAHbB4dfEavOJK06wvg6modSqW-J8CVV0MK7ok2issWbfvfA@mail.gmail.com>
On 13/10/2021 07.22, Yafang Shao wrote:
> On Wed, Oct 13, 2021 at 2:33 AM Matthew Wilcox (Oracle)
> <willy@infradead.org> wrote:
>>
>> Instead of calling snprintf(), just append '|' by hand.
>>
>> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
>> ---
>> 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
next prev parent reply other threads:[~2021-10-13 9:59 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-12 18:26 [PATCH 0/5] Improvements to %pGp Matthew Wilcox (Oracle)
2021-10-12 18:26 ` [PATCH 1/5] test_printf: Make pft array const Matthew Wilcox (Oracle)
2021-10-13 5:20 ` Yafang Shao
2021-10-15 9:21 ` Petr Mladek
2021-10-18 5:32 ` Anshuman Khandual
2021-10-12 18:26 ` [PATCH 2/5] test_printf: Assign all flags to page_flags Matthew Wilcox (Oracle)
2021-10-13 5:20 ` Yafang Shao
2021-10-13 9:25 ` Kirill A. Shutemov
2021-10-15 10:22 ` Petr Mladek
2021-10-18 5:33 ` Anshuman Khandual
2021-10-15 10:14 ` Petr Mladek
2021-10-12 18:26 ` [PATCH 3/5] test_printf: Remove custom appending of '|' Matthew Wilcox (Oracle)
2021-10-13 5:21 ` Yafang Shao
2021-10-15 10:23 ` Petr Mladek
2021-10-18 5:41 ` Anshuman Khandual
2021-10-12 18:26 ` [PATCH 4/5] test_printf: Append '|' more efficiently Matthew Wilcox (Oracle)
2021-10-13 5:22 ` Yafang Shao
2021-10-13 9:27 ` Kirill A. Shutemov
2021-10-18 5:42 ` Anshuman Khandual
2021-10-13 9:59 ` Rasmus Villemoes [this message]
2021-10-15 10:37 ` Petr Mladek
2021-10-12 18:26 ` [PATCH 5/5] vsprintf: Make %pGp print the hex value Matthew Wilcox (Oracle)
2021-10-13 5:24 ` Yafang Shao
2021-10-15 10:55 ` Petr Mladek
2021-10-27 11:28 ` Petr Mladek
2021-10-18 6:13 ` Anshuman Khandual
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=18622fb5-c4cd-7e4c-b295-e06837261fc5@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=laoar.shao@gmail.com \
--cc=linux-mm@kvack.org \
--cc=pmladek@suse.com \
--cc=senozhatsky@chromium.org \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).