Skip to content

Commit

Permalink
net: Use csum_replace_... and csum_sub() helpers instead of opencoding
Browse files Browse the repository at this point in the history
In a couple places, open coded calculation can be avoided
and replaced by the equivalent csum_replace4() and
csum_replace_by_diff().

There's also one place where csum_sub() should be used instead of
csum_add().

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
  • Loading branch information
chleroy authored and intel-lab-lkp committed Feb 17, 2022
1 parent c8b441d commit cec9ed7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions net/core/utils.c
Expand Up @@ -476,9 +476,9 @@ void inet_proto_csum_replace_by_diff(__sum16 *sum, struct sk_buff *skb,
__wsum diff, bool pseudohdr)
{
if (skb->ip_summed != CHECKSUM_PARTIAL) {
*sum = csum_fold(csum_add(diff, ~csum_unfold(*sum)));
csum_replace_by_diff(sum, diff);
if (skb->ip_summed == CHECKSUM_COMPLETE && pseudohdr)
skb->csum = ~csum_add(diff, ~skb->csum);
skb->csum = ~csum_sub(diff, skb->csum);
} else if (pseudohdr) {
*sum = ~csum_fold(csum_add(diff, csum_unfold(*sum)));
}
Expand Down
2 changes: 1 addition & 1 deletion net/netfilter/nft_payload.c
Expand Up @@ -557,7 +557,7 @@ const struct nft_expr_ops nft_payload_fast_ops = {

static inline void nft_csum_replace(__sum16 *sum, __wsum fsum, __wsum tsum)
{
*sum = csum_fold(csum_add(csum_sub(~csum_unfold(*sum), fsum), tsum));
csum_replace4(sum, fsum, tsum);
if (*sum == 0)
*sum = CSUM_MANGLED_0;
}
Expand Down

0 comments on commit cec9ed7

Please sign in to comment.