From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] speed up /proc/pid/stat, statm
Date: Wed, 1 Feb 2012 08:55:46 +0900 [thread overview]
Message-ID: <20120201085546.ecbf628d.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <20120131123612.6b60bdfc.akpm@linux-foundation.org>
On Tue, 31 Jan 2012 12:36:12 -0800
Andrew Morton <akpm@linux-foundation.org> wrote:
> On Tue, 31 Jan 2012 17:14:43 +0900
> KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:
>
> > +int seq_put_decimal_ll(struct seq_file *m, char delimiter,
> > + long long num)
> > +{
> > + if (num < 0) {
> > + if (m->count + 3 >= m->size) {
> > + m->count = m->size;
>
> Why is m->count udpated even thought we didn't write any data?
> seq_put_decimal_ull() does it too.
>
seq_xxxx functions set m->count == m->size when it finds possible buffer overflow.
If m->count == m->size after ->show(), buffer will be freed and twice size buffer
will be re-allocated, and retry.
If we don't set m->count == m->size here, following seq_putc() will succeed and
we'll see corrupted outputs.
Thanks,
-Kame
> > + return -1;
> > + }
> > + if (delimiter)
> > + m->buf[m->count++] = delimiter;
> > + num = -num;
> > + delimiter = '-';
> > + }
> > + return seq_put_decimal_ull(m, delimiter, num);
> > +
> > +}
> > +EXPORT_SYMBOL(seq_put_decimal_ll);
>
next prev parent reply other threads:[~2012-01-31 23:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-31 8:14 [PATCH] speed up /proc/pid/stat, statm KAMEZAWA Hiroyuki
2012-01-31 20:36 ` Andrew Morton
2012-01-31 23:55 ` KAMEZAWA Hiroyuki [this message]
2012-02-01 5:54 ` Eric Dumazet
2012-02-01 8:56 ` KAMEZAWA Hiroyuki
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=20120201085546.ecbf628d.kamezawa.hiroyu@jp.fujitsu.com \
--to=kamezawa.hiroyu@jp.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.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).