[PATCH] seq_file: fix condition while loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Yi Li <yilikernel@xxxxxxxxx>

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@xxxxxxxxx>
---
 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






[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux