Linux MM tree latest commits
 help / color / mirror / Atom feed
From: akpm@linux-foundation.org
To: biannm@cn.fujitsu.com, viro@zeniv.linux.org.uk,
	mm-commits@vger.kernel.org
Subject: - seq_file-fix-bug-when-seq_read-reads-nothing.patch removed from -mm tree
Date: Thu, 28 Aug 2008 14:30:05 -0700	[thread overview]
Message-ID: <200808282130.m7SLU60T015388@imap1.linux-foundation.org> (raw)


The patch titled
     seq_file(): fix bug when seq_read() reads nothing
has been removed from the -mm tree.  Its filename was
     seq_file-fix-bug-when-seq_read-reads-nothing.patch

This patch was dropped because an alternative patch was merged

The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/

------------------------------------------------------
Subject: seq_file(): fix bug when seq_read() reads nothing
From: Bian Naimeng <biannm@cn.fujitsu.com>

When I used seq_file to read a proc file, I got a bug in seq_read().  If
show() skips the first element or the size of first element is 0, and the
size of second element is larger than the seq_file->size at the same time,
seq_read will return 0, so nothing can be read from the proc file.

So, if seq_read() returns because it finds the element is bigger than the
m->buf, it must make sure that either some date was filled to m->buf by
show(), or some data was flushed to the user buf beforehand.  If not, it
should increase the m->buf until it can read this element.

[akpm@linux-foundation.org: fix comment]
Signed-off-by: Bian Naimeng <biannm@cn.fujitsu.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 fs/seq_file.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff -puN fs/seq_file.c~seq_file-fix-bug-when-seq_read-reads-nothing fs/seq_file.c
--- a/fs/seq_file.c~seq_file-fix-bug-when-seq_read-reads-nothing
+++ a/fs/seq_file.c
@@ -107,6 +107,7 @@ ssize_t seq_read(struct file *file, char
 		if (!size)
 			goto Done;
 	}
+First_record:
 	/* we need at least one record in buffer */
 	while (1) {
 		pos = m->index;
@@ -145,8 +146,18 @@ Fill:
 		err = m->op->show(m, p);
 		if (m->count == m->size || err) {
 			m->count = offs;
-			if (likely(err <= 0))
+			if (err < 0)
 				break;
+			/*
+			 * If no data was flushed to the user buf and nothing
+			 * was read by show() beforehand, we should advance the
+			 * m->buf until it can read this element.
+			 */
+			if (err == 0 && m->count == 0 && copied == 0) {
+				m->index = next;
+				m->op->stop(m, p);
+				goto First_record;
+			}
 		}
 		pos = next;
 	}
_

Patches currently in -mm which might be from biannm@cn.fujitsu.com are

seq_file-fix-bug-when-seq_read-reads-nothing.patch


                 reply	other threads:[~2008-08-28 21:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=200808282130.m7SLU60T015388@imap1.linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=biannm@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mm-commits@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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