* [PATCH] seq_file: fix condition while loop
@ 2019-10-31 11:38 Yi Li
2019-10-31 14:06 ` Al Viro
0 siblings, 1 reply; 3+ messages in thread
From: Yi Li @ 2019-10-31 11:38 UTC (permalink / raw)
To: linux-fsdevel; +Cc: yili, Yi Li, Alexander Viro, linux-kernel
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] seq_file: fix condition while loop
2019-10-31 11:38 [PATCH] seq_file: fix condition while loop Yi Li
@ 2019-10-31 14:06 ` Al Viro
2019-11-01 5:48 ` 李义
0 siblings, 1 reply; 3+ messages in thread
From: Al Viro @ 2019-10-31 14:06 UTC (permalink / raw)
To: Yi Li; +Cc: linux-fsdevel, Yi Li, linux-kernel
On Thu, Oct 31, 2019 at 07:38:21PM +0800, Yi Li wrote:
> 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.
IDGI. PTR_ERR() is not going to cause any kind of undefined behaviour for
any valid pointer and it's trivial to evaluate. What's the point?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] seq_file: fix condition while loop
2019-10-31 14:06 ` Al Viro
@ 2019-11-01 5:48 ` 李义
0 siblings, 0 replies; 3+ messages in thread
From: 李义 @ 2019-11-01 5:48 UTC (permalink / raw)
To: Al Viro; +Cc: Yi Li, linux-fsdevel, linux-kernel
On Thu, Oct 31, 2019 at 10:06 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> On Thu, Oct 31, 2019 at 07:38:21PM +0800, Yi Li wrote:
> > 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.
>
> IDGI. PTR_ERR() is not going to cause any kind of undefined behaviour for
> any valid pointer and it's trivial to evaluate. What's the point?
This patch doesn't introduce any functional changes.
Sorry for the noise..
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-11-01 5:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-31 11:38 [PATCH] seq_file: fix condition while loop Yi Li
2019-10-31 14:06 ` Al Viro
2019-11-01 5:48 ` 李义
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).