net: use helper skb_ensure_writable in skb_checksum_help and skb_crc32c_csum_help
Subsystems (2)
RFC PATCH 1/1 net: use helper skb_ensure_writable in skb_checksum_help and skb_crc32c_csum_help
Instead of open-coding making the checksum writable we can use an appropriate helper. skb_ensure_writable is a candidate, however we might also use skb_header_unclone. Hints welcome.
Signed-off-by Heiner Kallweit <[email protected]>
--- net/core/dev.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
net/core/dev.c +8 -12
@@ -2939,12 +2939,9 @@ int skb_checksum_help(struct sk_buff *skb) offset += skb->csum_offset;BUG_ON (offset +sizeof (__sum16) >skb_headlen (skb)); -if (skb_cloned (skb) && - !skb_clone_writable (skb, offset +sizeof (__sum16))) { - ret =pskb_expand_head (skb,0 ,0 ,GFP_ATOMIC ); -if (ret) - goto out; - } + ret =skb_ensure_writable (skb, offset +sizeof (__sum16)); +if (ret) + goto out; *(__sum16 *)(skb->data + offset) =csum_fold (csum) ?:CSUM_MANGLED_0 ; out_set_summed:
@@ -2979,12 +2976,11 @@ int skb_crc32c_csum_help(struct sk_buff *skb) ret = -EINVAL ; goto out; } -if (skb_cloned (skb) && - !skb_clone_writable (skb, offset +sizeof (__le32))) { - ret =pskb_expand_head (skb,0 ,0 ,GFP_ATOMIC ); -if (ret) - goto out; - } + + ret =skb_ensure_writable (skb, offset +sizeof (__le32)); +if (ret) + goto out; + crc32c_csum =cpu_to_le32 (~__skb_checksum (skb, start, skb->len - start, ~(__u32 )0 , crc32c_csum_stub));
Signature · 1 line
2.22.0
David Miller
maintainerFrom: Heiner Kallweit <[email protected]>
Date: Wed, 24 Jul 2019 23:47:49 +0200
Quoted 5 lines
Instead of open-coding making the checksum writable we can use an appropriate helper.
skb_ensure_writableis a candidate, however we might also useskb_header_unclone. Hints welcome.Signed-off-by Heiner Kallweit <[email protected]>
FWIW these conversions look accurate to me.
The only real difference is the perhaps unnecessary pskb_may_pull() check.