seq_file: always clear m->count when we free m->buf
authorAl Viro <viro@ZenIV.linux.org.uk>
Tue, 19 Nov 2013 01:20:43 +0000 (01:20 +0000)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 19 Nov 2013 03:07:53 +0000 (19:07 -0800)
Once we'd freed m->buf, m->count should become zero - we have no valid
contents reachable via m->buf.

Reported-by: Charley (Hao Chuan) Chu <charley.chu@broadcom.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/seq_file.c

index 1cd2388ca5bd7c11cd504b3a65ba67969cd936b5..1d641bb108d239f2476d862f0ce9e366c299762c 100644 (file)
@@ -136,6 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
 Eoverflow:
        m->op->stop(m, p);
        kfree(m->buf);
+       m->count = 0;
        m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
        return !m->buf ? -ENOMEM : -EAGAIN;
 }
@@ -232,10 +233,10 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
                        goto Fill;
                m->op->stop(m, p);
                kfree(m->buf);
+               m->count = 0;
                m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
                if (!m->buf)
                        goto Enomem;
-               m->count = 0;
                m->version = 0;
                pos = m->index;
                p = m->op->start(m, &pos);