Skip to content

Commit

Permalink
net: caif: use skb helpers instead of open-coding them
Browse files Browse the repository at this point in the history
Use existing skb_put_data() and skb_trim() instead of open-coding them,
with the skb_put_data() first so that logically, `skb` still contains the
data to be copied in its data..tail area when skb_put_data() reads it.
This change on its own is a cleanup, and it is also necessary for potential
future integration of skbuffs with things like KASAN.

Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jann Horn authored and David S. Miller committed Feb 17, 2019
1 parent 6a79507 commit 1eb0016
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions net/caif/cfpkt_skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,12 @@ struct cfpkt *cfpkt_append(struct cfpkt *dstpkt,
if (tmppkt == NULL)
return NULL;
tmp = pkt_to_skb(tmppkt);
skb_set_tail_pointer(tmp, dstlen);
tmp->len = dstlen;
memcpy(tmp->data, dst->data, dstlen);
skb_put_data(tmp, dst->data, dstlen);
cfpkt_destroy(dstpkt);
dst = tmp;
}
memcpy(skb_tail_pointer(dst), add->data, skb_headlen(add));
skb_put_data(dst, add->data, skb_headlen(add));
cfpkt_destroy(addpkt);
dst->tail += addlen;
dst->len += addlen;
return skb_to_pkt(dst);
}

Expand Down Expand Up @@ -359,13 +355,11 @@ struct cfpkt *cfpkt_split(struct cfpkt *pkt, u16 pos)
if (skb2 == NULL)
return NULL;

skb_put_data(skb2, split, len2nd);

/* Reduce the length of the original packet */
skb_set_tail_pointer(skb, pos);
skb->len = pos;
skb_trim(skb, pos);

memcpy(skb2->data, split, len2nd);
skb2->tail += len2nd;
skb2->len += len2nd;
skb2->priority = skb->priority;
return skb_to_pkt(skb2);
}
Expand Down

0 comments on commit 1eb0016

Please sign in to comment.