linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Quanfa Fu <quanfafu@gmail.com>
To: rostedt@goodmis.org, mhiramat@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	Quanfa Fu <quanfafu@gmail.com>
Subject: [PATCH v3] tracing/eprobe: no need to check for negative ret value for snprintf
Date: Mon,  9 Jan 2023 12:06:25 +0800	[thread overview]
Message-ID: <20230109040625.3259642-1-quanfafu@gmail.com> (raw)

No need to check for negative return value from snprintf() as the
code does not return negative values.

Signed-off-by: Quanfa Fu <quanfafu@gmail.com>

-----
V2 -> V3: continue to use snprintf
V1 -> V2: memory allc uses kzalloc and replace snprintf with memcpy
---
 kernel/trace/trace_eprobe.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c
index 352b65e2b910..594ac1d086aa 100644
--- a/kernel/trace/trace_eprobe.c
+++ b/kernel/trace/trace_eprobe.c
@@ -923,17 +923,13 @@ static int trace_eprobe_parse_filter(struct trace_eprobe *ep, int argc, const ch
 
 	p = ep->filter_str;
 	for (i = 0; i < argc; i++) {
-		ret = snprintf(p, len, "%s ", argv[i]);
-		if (ret < 0)
-			goto error;
-		if (ret > len) {
-			ret = -E2BIG;
-			goto error;
-		}
+		if (i)
+			ret = snprintf(p, len, " %s", argv[i]);
+		else
+			ret = snprintf(p, len, "%s", argv[i]);
 		p += ret;
 		len -= ret;
 	}
-	p[-1] = '\0';
 
 	/*
 	 * Ensure the filter string can be parsed correctly. Note, this
-- 
2.31.1


             reply	other threads:[~2023-01-09  4:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09  4:06 Quanfa Fu [this message]
2023-01-09 14:59 ` [PATCH v3] tracing/eprobe: no need to check for negative ret value for snprintf Masami Hiramatsu
2023-01-09 15:12   ` Steven Rostedt
2023-01-10  0:29     ` Masami Hiramatsu

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=20230109040625.3259642-1-quanfafu@gmail.com \
    --to=quanfafu@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@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).