Messages in this thread | | | Date | Wed, 1 Feb 2012 08:55:46 +0900 | From | KAMEZAWA Hiroyuki <> | Subject | Re: [PATCH] speed up /proc/pid/stat, statm |
| |
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); >
| |