diff options
author | Matthew Wilcox (Oracle) <willy@infradead.org> | 2021-10-19 17:26:20 +0300 |
---|---|---|
committer | Petr Mladek <pmladek@suse.com> | 2021-10-27 14:40:13 +0300 |
commit | 507f98603607d43cb76ed39c370c4dc1ed6a94f9 (patch) | |
tree | 1a7c0566deea60e0cc95e2a222d0003f1dfef133 /lib/test_printf.c | |
parent | 5b358b0de963f822226bfee916fb53c80bae4000 (diff) | |
download | linux-507f98603607d43cb76ed39c370c4dc1ed6a94f9.tar.xz |
test_printf: Append strings more efficiently
Use scnprintf instead of snprintf + strlen.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Yafang Shao <laoar.shao@gmail.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20211019142621.2810043-5-willy@infradead.org
Diffstat (limited to 'lib/test_printf.c')
-rw-r--r-- | lib/test_printf.c | 18 |
1 files 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; } |