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>
This commit is contained in:
@@ -80,16 +80,18 @@ static inline __sum16 csum16_sub(__sum16 csum, __be16 addend)
|
|||||||
return csum16_add(csum, ~addend);
|
return csum16_add(csum, ~addend);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline __wsum csum_shift(__wsum sum, int offset)
|
||||||
|
{
|
||||||
|
/* rotate sum to align it with a 16b boundary */
|
||||||
|
if (offset & 1)
|
||||||
|
return (__force __wsum)ror32((__force u32)sum, 8);
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
static inline __wsum
|
static inline __wsum
|
||||||
csum_block_add(__wsum csum, __wsum csum2, int offset)
|
csum_block_add(__wsum csum, __wsum csum2, int offset)
|
||||||
{
|
{
|
||||||
u32 sum = (__force u32)csum2;
|
return csum_add(csum, csum_shift(csum2, offset));
|
||||||
|
|
||||||
/* rotate sum to align it with a 16b boundary */
|
|
||||||
if (offset & 1)
|
|
||||||
sum = ror32(sum, 8);
|
|
||||||
|
|
||||||
return csum_add(csum, (__force __wsum)sum);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline __wsum
|
static inline __wsum
|
||||||
|
|||||||
@@ -1781,8 +1781,8 @@ size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *_csstate,
|
|||||||
if (unlikely(iov_iter_is_pipe(i)))
|
if (unlikely(iov_iter_is_pipe(i)))
|
||||||
return csum_and_copy_to_pipe_iter(addr, bytes, _csstate, i);
|
return csum_and_copy_to_pipe_iter(addr, bytes, _csstate, i);
|
||||||
|
|
||||||
sum = csstate->csum;
|
sum = csum_shift(csstate->csum, csstate->off);
|
||||||
off = csstate->off;
|
off = 0;
|
||||||
if (unlikely(iov_iter_is_discard(i))) {
|
if (unlikely(iov_iter_is_discard(i))) {
|
||||||
WARN_ON(1); /* for now */
|
WARN_ON(1); /* for now */
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1817,8 +1817,8 @@ size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *_csstate,
|
|||||||
off += v.bv_len;
|
off += v.bv_len;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
csstate->csum = sum;
|
csstate->csum = csum_shift(sum, csstate->off);
|
||||||
csstate->off = off;
|
csstate->off += bytes;
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(csum_and_copy_to_iter);
|
EXPORT_SYMBOL(csum_and_copy_to_iter);
|
||||||
|
|||||||
Reference in New Issue
Block a user