Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

csum_and_copy_to_iter(): massage into form closer to csum_and_copy_from_iter()

Namely, have off counted starting from 0 rather than from csstate->off.
To compensate we need to shift the initial value (csstate->sum) (rotate
by 8 bits, as usual for csum) and do the same after we are finished adding
the pieces up.

What we get out of that is a bit more redundancy in our variables - from
is always equal to addr + off, which will be useful several commits down
the road.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro 594e450b f0b65f39

+13 -11
+9 -7
include/net/checksum.h
··· 80 80 return csum16_add(csum, ~addend); 81 81 } 82 82 83 + static inline __wsum csum_shift(__wsum sum, int offset) 84 + { 85 + /* rotate sum to align it with a 16b boundary */ 86 + if (offset & 1) 87 + return (__force __wsum)ror32((__force u32)sum, 8); 88 + return sum; 89 + } 90 + 83 91 static inline __wsum 84 92 csum_block_add(__wsum csum, __wsum csum2, int offset) 85 93 { 86 - u32 sum = (__force u32)csum2; 87 - 88 - /* rotate sum to align it with a 16b boundary */ 89 - if (offset & 1) 90 - sum = ror32(sum, 8); 91 - 92 - return csum_add(csum, (__force __wsum)sum); 94 + return csum_add(csum, csum_shift(csum2, offset)); 93 95 } 94 96 95 97 static inline __wsum
+4 -4
lib/iov_iter.c
··· 1781 1781 if (unlikely(iov_iter_is_pipe(i))) 1782 1782 return csum_and_copy_to_pipe_iter(addr, bytes, _csstate, i); 1783 1783 1784 - sum = csstate->csum; 1785 - off = csstate->off; 1784 + sum = csum_shift(csstate->csum, csstate->off); 1785 + off = 0; 1786 1786 if (unlikely(iov_iter_is_discard(i))) { 1787 1787 WARN_ON(1); /* for now */ 1788 1788 return 0; ··· 1817 1817 off += v.bv_len; 1818 1818 }) 1819 1819 ) 1820 - csstate->csum = sum; 1821 - csstate->off = off; 1820 + csstate->csum = csum_shift(sum, csstate->off); 1821 + csstate->off += bytes; 1822 1822 return bytes; 1823 1823 } 1824 1824 EXPORT_SYMBOL(csum_and_copy_to_iter);