mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: liuyang34 <yangliuxm34@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org
Cc: liuyang34 <liuyang34@xiaomi.com>
Subject: [PATCH] trace: code optimization
Date: Thu,  9 Jan 2020 17:12:17 +0800	[thread overview]
Message-ID: <27225bf0ec9b4e2f3d313456aee75e294361d550.1578561009.git.liuyang34@xiaomi.com> (raw)
In-Reply-To: <cover.1578561009.git.liuyang34@xiaomi.com>

use scnprintf instead of snprinr and no need to check
the return size again

Signed-off-by: liuyang34 <liuyang34@xiaomi.com>
---
 kernel/trace/trace_stack.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
index c557f42..7b15e9a 100644
--- a/kernel/trace/trace_stack.c
+++ b/kernel/trace/trace_stack.c
@@ -329,9 +329,7 @@ stack_max_size_read(struct file *filp, char __user *ubuf,
 	char buf[64];
 	int r;
 
-	r = snprintf(buf, sizeof(buf), "%ld\n", *ptr);
-	if (r > sizeof(buf))
-		r = sizeof(buf);
+	r = scnprintf(buf, sizeof(buf), "%ld\n", *ptr);
 	return simple_read_from_buffer(ubuf, count, ppos, buf, r);
 }
 
-- 
2.7.4


WARNING: multiple messages have this Message-ID
From: liuyang34 <yangliuxm34@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org
Cc: liuyang34 <liuyang34@xiaomi.com>
Subject: [RESEND PATCH] trace: code optimization
Date: Fri, 10 Jan 2020 08:57:04 +0800	[thread overview]
Message-ID: <27225bf0ec9b4e2f3d313456aee75e294361d550.1578561009.git.liuyang34@xiaomi.com> (raw)
Message-ID: <20200110005704.uBMnxTvuVyW2xGC38tgnSxFophSupLbsUGYG1nSPEQk@z> (raw)
In-Reply-To: <cover.1578561009.git.liuyang34@xiaomi.com>

use scnprintf instead of snprintf and no need to check
the return size again

Signed-off-by: liuyang <liuyang34@xiaomi.com>
---
 kernel/trace/trace_stack.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
index c557f42..7b15e9a 100644
--- a/kernel/trace/trace_stack.c
+++ b/kernel/trace/trace_stack.c
@@ -329,9 +329,7 @@ stack_max_size_read(struct file *filp, char __user *ubuf,
 	char buf[64];
 	int r;
 
-	r = snprintf(buf, sizeof(buf), "%ld\n", *ptr);
-	if (r > sizeof(buf))
-		r = sizeof(buf);
+	r = scnprintf(buf, sizeof(buf), "%ld\n", *ptr);
 	return simple_read_from_buffer(ubuf, count, ppos, buf, r);
 }
 
-- 
2.7.4


       reply	other threads:[~2020-01-09  9:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1578561009.git.liuyang34@xiaomi.com>
2020-01-09  9:12 ` liuyang34 [this message]
2020-01-09 13:16   ` Markus Elfring
2020-01-09 14:32     ` Steven Rostedt
2020-01-10  0:57   ` [RESEND PATCH] " liuyang34

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=27225bf0ec9b4e2f3d313456aee75e294361d550.1578561009.git.liuyang34@xiaomi.com \
    --to=yangliuxm34@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuyang34@xiaomi.com \
    --cc=mingo@redhat.com \
    --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

all inboxes | Powered by JetHome®