public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Amerigo Wang <amwang@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, Amerigo Wang <amwang@redhat.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: [Patch] RCU trace: use scnprintf instead of snprintf
Date: Tue, 12 May 2009 06:04:15 -0400	[thread overview]
Message-ID: <20090512100504.6008.52782.sendpatchset@localhost.localdomain> (raw)


snprintf can return more than the size of buffer, this case
is not expected here, obviously. Use scnprintf instead.

Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>

---
diff --git a/kernel/rcupreempt_trace.c b/kernel/rcupreempt_trace.c
index 7c2665c..4ea4300 100644
--- a/kernel/rcupreempt_trace.c
+++ b/kernel/rcupreempt_trace.c
@@ -234,11 +234,11 @@ static ssize_t rcuctrs_read(struct file *filp, char __user *buffer,
 
 	mutex_lock(&rcupreempt_trace_mutex);
 
-	cnt += snprintf(&rcupreempt_trace_buf[cnt], RCUPREEMPT_TRACE_BUF_SIZE,
+	cnt += scnprintf(&rcupreempt_trace_buf[cnt], RCUPREEMPT_TRACE_BUF_SIZE,
 				"CPU last cur F M\n");
 	for_each_online_cpu(cpu) {
 		long *flipctr = rcupreempt_flipctr(cpu);
-		cnt += snprintf(&rcupreempt_trace_buf[cnt],
+		cnt += scnprintf(&rcupreempt_trace_buf[cnt],
 				RCUPREEMPT_TRACE_BUF_SIZE - cnt,
 					"%3d %4ld %3ld %d %d\n",
 			       cpu,
@@ -247,12 +247,12 @@ static ssize_t rcuctrs_read(struct file *filp, char __user *buffer,
 			       rcupreempt_flip_flag(cpu),
 			       rcupreempt_mb_flag(cpu));
 	}
-	cnt += snprintf(&rcupreempt_trace_buf[cnt],
+	cnt += scnprintf(&rcupreempt_trace_buf[cnt],
 			RCUPREEMPT_TRACE_BUF_SIZE - cnt,
 			"ggp = %ld, state = %s\n",
 			rcu_batches_completed(),
 			rcupreempt_try_flip_state_name());
-	cnt += snprintf(&rcupreempt_trace_buf[cnt],
+	cnt += scnprintf(&rcupreempt_trace_buf[cnt],
 			RCUPREEMPT_TRACE_BUF_SIZE - cnt,
 			"\n");
 	bcount = simple_read_from_buffer(buffer, count, ppos,

             reply	other threads:[~2009-05-12 10:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-12 10:04 Amerigo Wang [this message]
2009-05-12 16:15 ` [Patch] RCU trace: use scnprintf instead of snprintf Paul E. McKenney

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=20090512100504.6008.52782.sendpatchset@localhost.localdomain \
    --to=amwang@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    /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