networking: introduce and use skb_put_data()

A common pattern with skb_put() is to just want to memcpy()
some data into the new space, introduce skb_put_data() for
this.

An spatch similar to the one for skb_put_zero() converts many
of the places using it:

    @@
    identifier p, p2;
    expression len, skb, data;
    type t, t2;
    @@
    (
    -p = skb_put(skb, len);
    +p = skb_put_data(skb, data, len);
    |
    -p = (t)skb_put(skb, len);
    +p = skb_put_data(skb, data, len);
    )
    (
    p2 = (t2)p;
    -memcpy(p2, data, len);
    |
    -memcpy(p, data, len);
    )

    @@
    type t, t2;
    identifier p, p2;
    expression skb, data;
    @@
    t *p;
    ...
    (
    -p = skb_put(skb, sizeof(t));
    +p = skb_put_data(skb, data, sizeof(t));
    |
    -p = (t *)skb_put(skb, sizeof(t));
    +p = skb_put_data(skb, data, sizeof(t));
    )
    (
    p2 = (t2)p;
    -memcpy(p2, data, sizeof(*p));
    |
    -memcpy(p, data, sizeof(*p));
    )

    @@
    expression skb, len, data;
    @@
    -memcpy(skb_put(skb, len), data, len);
    +skb_put_data(skb, data, len);

(again, manually post-processed to retain some comments)

Reviewed-by: Stephen Hemminger <[email protected]>
Signed-off-by: Johannes Berg <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
This commit is contained in:
Johannes Berg 2017-06-16 14:29:20 +02:00 • committed by David S. Miller
commit 59ae1d127a
252 changed files with 622 additions and 741 deletions

View file

@ -355,7 +355,7 @@ static struct sk_buff *ipw_packet_received_skb(unsigned char *data,
if (skb == NULL)
return NULL;
skb_reserve(skb, 2);
memcpy(skb_put(skb, length), data, length);
skb_put_data(skb, data, length);
return skb;
}

View file

@ -2688,7 +2688,7 @@ static void gsm_mux_rx_netchar(struct gsm_dlci *dlci,
return;
}
skb_reserve(skb, NET_IP_ALIGN);
memcpy(skb_put(skb, size), in_buf, size);
skb_put_data(skb, in_buf, size);
skb->dev = net;
skb->protocol = htons(ETH_P_IP);

View file

@ -7960,7 +7960,7 @@ static void hdlcdev_rx(struct mgsl_struct *info, char *buf, int size)
return;
}
memcpy(skb_put(skb, size), buf, size);
skb_put_data(skb, buf, size);
skb->protocol = hdlc_type_trans(skb, dev);

View file

@ -1755,7 +1755,7 @@ static void hdlcdev_rx(struct slgt_info *info, char *buf, int size)
return;
}
memcpy(skb_put(skb, size), buf, size);
skb_put_data(skb, buf, size);
skb->protocol = hdlc_type_trans(skb, dev);

View file

@ -1874,7 +1874,7 @@ static void hdlcdev_rx(SLMP_INFO *info, char *buf, int size)
return;
}
memcpy(skb_put(skb, size), buf, size);
skb_put_data(skb, buf, size);
skb->protocol = hdlc_type_trans(skb, dev);