net: core: Use csum_replace_by_diff() and csum_sub() instead of opencoding
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Fri, 18 Feb 2022 08:03:48 +0000 (09:03 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 21 Feb 2022 11:40:44 +0000 (11:40 +0000)
Open coded calculation can be avoided and replaced by the
equivalent csum_replace_by_diff() and csum_sub().

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/utils.c

index 1f31a39..938495b 100644 (file)
@@ -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)));
        }