lkml.org 
[lkml]   [2020]   [Nov]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 1/6] seq_file: add seq_read_iter
On Tue, Nov 10, 2020 at 3:20 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> Any objections to the following?

Well, I don't _object_, but I find it ugly.

And I think both the old and the "fixed" code is wrong when an EFAULT
happens in the middle.

Yes, we can just return EFAULT. But for read() and write() we really
try to do the proper partial returns in other places, why not here?

IOW, why isn't the proper fix just something like this:

diff --git a/fs/seq_file.c b/fs/seq_file.c
index 3b20e21604e7..ecc6909b71f5 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -209,7 +209,8 @@ ssize_t seq_read_iter(struct kiocb *iocb,
struct iov_iter *iter)
/* if not empty - flush it first */
if (m->count) {
n = min(m->count, size);
- if (copy_to_iter(m->buf + m->from, n, iter) != n)
+ n = copy_to_iter(m->buf + m->from, n, iter);
+ if (!n)
goto Efault;
m->count -= n;
m->from += n;

which should get the "efault in the middle" case roughly right (ie the
usual "exact byte alignment and page crosser" caveats apply).

Linus

\
 
 \ /
  Last update: 2020-11-11 18:55    [W:0.089 / U:1.744 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site