lkml.org 
[lkml]   [2014]   [Nov]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/4] inet: Add skb_copy_datagram_iter
On Thu, Nov 06, 2014 at 04:28:18PM +0800, Herbert Xu wrote:
> + if (copy_to_iter(skb->data + offset, copy, to))
> + goto fault;

Sorry, no - copy_to_iter() returns the number of bytes copied, not 0 or -EFAULT.

> + vaddr = kmap(page);
> + err = copy_to_iter(vaddr + frag->page_offset +
> + offset - start, copy, to);
> + kunmap(page);
> + if (err)
> + goto fault;

And that one should be
copied = copy_page_to_iter(page, frag->page_offset +
offset - start, copy, to);
if (copied != copy)
goto fault;

Don't bother with kmap(), vaddr and all that shite. The primitive is
copy_page_to_iter(page, offset_in_page, nbytes, iter)
it does all needed kmap itself and it's smart enough to use kmap_atomic
when it can get away with that. Similar for copy_page_from_iter().

Both of those (as well as copy_{to,from}_iter()) advance iov_iter and return
the number of bytes actually copied. So the check for EFAULT is "it has copied
less than you've asked it to copy *and* you haven't run out that iov_iter".
The second part is guaranteed to be true in this case - your code makes sure
that 'copy' is no more than the space left in iterator.

In general, this check would be spelled
if (copied != copy && iov_iter_count(to))
goto fault;


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