From: Yi Li <yili@winhong.com>
To: linux-fsdevel@vger.kernel.org
Cc: yili@winhong.com, Yi Li <yilikernel@gmail.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
linux-kernel@vger.kernel.org
Subject: [PATCH] seq_file: fix condition while loop
Date: Thu, 31 Oct 2019 19:38:21 +0800 [thread overview]
Message-ID: <1572521901-5070-1-git-send-email-yili@winhong.com> (raw)
From: Yi Li <yilikernel@gmail.com>
Use the break condition of loop body.
PTR_ERR has some meanings when p is illegal,and return 0 when p is null.
set the err = 0 on the next iteration if err > 0.
Signed-off-by: Yi Li <yilikernel@gmail.com>
---
fs/seq_file.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 1600034..3796d4f 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -107,9 +107,10 @@ static int traverse(struct seq_file *m, loff_t offset)
}
p = m->op->start(m, &m->index);
while (p) {
- error = PTR_ERR(p);
- if (IS_ERR(p))
+ if (IS_ERR(p)) {
+ error = PTR_ERR(p);
break;
+ }
error = m->op->show(m, p);
if (error < 0)
break;
@@ -222,10 +223,11 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
/* we need at least one record in buffer */
m->from = 0;
p = m->op->start(m, &m->index);
- while (1) {
- err = PTR_ERR(p);
- if (!p || IS_ERR(p))
+ while (p) {
+ if (IS_ERR(p)) {
+ err = PTR_ERR(p);
break;
+ }
err = m->op->show(m, p);
if (err < 0)
break;
@@ -233,6 +235,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
m->count = 0;
if (unlikely(!m->count)) {
p = m->op->next(m, p, &m->index);
+ err = 0;
continue;
}
if (m->count < m->size)
--
2.7.5
next reply other threads:[~2019-10-31 11:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-31 11:38 Yi Li [this message]
2019-10-31 14:06 ` [PATCH] seq_file: fix condition while loop Al Viro
2019-11-01 5:48 ` 李义
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=1572521901-5070-1-git-send-email-yili@winhong.com \
--to=yili@winhong.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=yilikernel@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;
as well as URLs for NNTP newsgroup(s).