From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: Alan Maguire <alan.maguire@oracle.com>,
Steven Rostedt <rostedt@goodmis.org>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: [PATCH] bpf: remove pointless code from bpf_do_trace_printk()
Date: Wed, 21 Apr 2021 21:07:36 +0200 [thread overview]
Message-ID: <20210421190736.1538217-1-linux@rasmusvillemoes.dk> (raw)
The comment is wrong. snprintf(buf, 16, "") and snprintf(buf, 16,
"%s", "") etc. will certainly put '\0' in buf[0]. The only case where
snprintf() does not guarantee a nul-terminated string is when it is
given a buffer size of 0 (which of course prevents it from writing
anything at all to the buffer).
Remove it before it gets cargo-culted elsewhere.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
kernel/trace/bpf_trace.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index b0c45d923f0f..4ee55df84cd3 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -412,9 +412,6 @@ static __printf(1, 0) int bpf_do_trace_printk(const char *fmt, ...)
va_start(ap, fmt);
ret = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
- /* vsnprintf() will not append null for zero-length strings */
- if (ret == 0)
- buf[0] = '\0';
trace_bpf_trace_printk(buf);
raw_spin_unlock_irqrestore(&trace_printk_lock, flags);
--
2.29.2
next reply other threads:[~2021-04-21 19:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-21 19:07 Rasmus Villemoes [this message]
2021-04-22 3:32 ` [PATCH] bpf: remove pointless code from bpf_do_trace_printk() Andrii Nakryiko
2021-04-22 7:13 ` Rasmus Villemoes
2021-04-22 9:23 ` Florent Revest
2021-04-22 10:09 ` Rasmus Villemoes
2021-04-22 12:36 ` Florent Revest
2021-04-22 15:34 ` Florent Revest
2021-04-22 15:43 ` Alexei Starovoitov
2021-04-22 15:46 ` Florent Revest
2021-04-22 18:38 ` Andrii Nakryiko
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=20210421190736.1538217-1-linux@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=alan.maguire@oracle.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.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).