From: Joe Perches <joe@perches.com>
To: Pranith Kumar <bobby.prani@gmail.com>
Cc: paulmck@linux.vnet.ibm.com, LKML <linux-kernel@vger.kernel.org>,
romanov.arya@gmail.com, Josh Triplett <josh@joshtriplett.org>
Subject: Re: [RFC PATCH] use snprintf instead of sprintf in rcu_torture_printk
Date: Thu, 19 Jun 2014 16:33:09 -0700 [thread overview]
Message-ID: <1403220789.2753.32.camel@joe-AO725> (raw)
In-Reply-To: <53A37140.3020003@gmail.com>
On Thu, 2014-06-19 at 19:24 -0400, Pranith Kumar wrote:
> (dropping some CCs)
>
> On 06/19/2014 05:00 PM, Paul E. McKenney wrote:
> > On Wed, Jun 18, 2014 at 12:49:42PM -0700, Joe Perches wrote:
> >>
> >> I believe the function doesn't work well.
> >>
> >> static void
> >> rcu_torture_stats_print(void)
> >> {
> >> int size = nr_cpu_ids * 200 + 8192;
> >> char *buf;
> >>
> >> buf = kmalloc(size, GFP_KERNEL);
> >> if (!buf) {
> >> pr_err("rcu-torture: Out of memory, need: %d\n", size);
> >> return;
> >> }
> >> rcu_torture_printk(buf);
> >> pr_alert("%s", buf);
> >> kfree(buf);
> >> }
> >>
> >> rcu_torture_printk simply fills buf
> >>
> >> btw: I believe the arguments should pass size and
> >> rcu_torture_printk should use snprintf/size
> >>
> >> but all printks are limited to a maximum of 1024
> >> bytes so the large allocation is senseless and
> >> would even if it worked, would likely need to be
> >> vmalloc/vfree
> >
> > Fair point!
> >
> > Pranith, Romanov, if you would like part of RCU that is less touchy
> > about random hacking, this would be a good place to start. Scripts in
> > tools/testing/selftests/rcutorture/bin do care about some of the format,
> > but the variable-length portion generated by cur_ops->stats() is as far
> > as I know only parsed by human eyes.
> >
>
> Here is a first run of the change. Please let me know if I am totally off. RFC. :)
>
> Three things on Todo list:
>
> * We need to check that we are using less than the allocated size of the buffer (used > size). (we are allocating a big buffer, so not sure if necessary)
> * Need to check with the scripts if they are working.
> * I used a loop for pr_alert(). I am not sure this is right, there should be a better way for printing large buffers
>
> If the overall structure is ok I will go ahead and check how the scripts are handling these changes.
[]
> diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
[]
> @@ -1130,17 +1134,23 @@ rcu_torture_printk(char *page)
> static void
> rcu_torture_stats_print(void)
> {
[]
> + /* printk can print only print LOG_LINE_MAX chars at a time */
> + while (used > 0) {
> + size_pr = pr_alert("%s", buf);
> + used -= size_pr;
> + buf += size_pr;
> + }
> + vfree(buf);
> }
You can't increment buf then vfree it.
Try a char *tmpbuf = buf, and increment it.
I suggest you check by strcspn(tmpbuf, "\n")
save the byte after, replace it with 0,
print, replace the 0 with saved byte, and
loop until end of buffer.
next prev parent reply other threads:[~2014-06-19 23:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-10 16:55 [RFC PATCH] checkpatch: Attempt to find unnecessary 'out of memory' messages Joe Perches
2014-06-11 7:47 ` Dan Carpenter
2014-06-11 16:01 ` Joe Perches
2014-06-14 7:40 ` Julia Lawall
2014-06-14 8:30 ` Joe Perches
2014-06-14 9:51 ` Julia Lawall
2014-06-18 19:33 ` Paul E. McKenney
2014-06-18 19:49 ` Joe Perches
2014-06-19 21:00 ` Paul E. McKenney
2014-06-19 23:24 ` [RFC PATCH] use snprintf instead of sprintf in rcu_torture_printk Pranith Kumar
2014-06-19 23:33 ` Joe Perches [this message]
2014-06-20 0:11 ` Pranith Kumar
2014-06-19 23:49 ` Paul E. McKenney
2014-06-20 0:13 ` Pranith Kumar
2014-06-20 4:54 ` Paul E. McKenney
2014-06-20 22:04 ` Joe Perches
2014-06-18 21:18 ` [RFC PATCH] checkpatch: Attempt to find unnecessary 'out of memory' messages Julia Lawall
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=1403220789.2753.32.camel@joe-AO725 \
--to=joe@perches.com \
--cc=bobby.prani@gmail.com \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=romanov.arya@gmail.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
all inboxes | Powered by JetHome®