541c694bec00371ae51266db743a3d7d3e05599a
[librecmc/librecmc.git] / target / linux / generic / patches-4.4 / 030-7-kaweth-use-skb_cow_head-to-deal-with-cloned-skbs.patch
1 From 39fba7835aacda65284a86e611774cbba71dac20 Mon Sep 17 00:00:00 2001
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Wed, 19 Apr 2017 09:59:26 -0700
4 Subject: [PATCH] kaweth: use skb_cow_head() to deal with cloned skbs
5
6 We can use skb_cow_head() to properly deal with clones,
7 especially the ones coming from TCP stack that allow their head being
8 modified. This avoids a copy.
9
10 Signed-off-by: Eric Dumazet <edumazet@google.com>
11 Cc: James Hughes <james.hughes@raspberrypi.org>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
13 ---
14  drivers/net/usb/kaweth.c | 18 ++++++------------
15  1 file changed, 6 insertions(+), 12 deletions(-)
16
17 --- a/drivers/net/usb/kaweth.c
18 +++ b/drivers/net/usb/kaweth.c
19 @@ -812,18 +812,12 @@ static netdev_tx_t kaweth_start_xmit(str
20         }
21  
22         /* We now decide whether we can put our special header into the sk_buff */
23 -       if (skb_cloned(skb) || skb_headroom(skb) < 2) {
24 -               /* no such luck - we make our own */
25 -               struct sk_buff *copied_skb;
26 -               copied_skb = skb_copy_expand(skb, 2, 0, GFP_ATOMIC);
27 -               dev_kfree_skb_irq(skb);
28 -               skb = copied_skb;
29 -               if (!copied_skb) {
30 -                       kaweth->stats.tx_errors++;
31 -                       netif_start_queue(net);
32 -                       spin_unlock_irq(&kaweth->device_lock);
33 -                       return NETDEV_TX_OK;
34 -               }
35 +       if (skb_cow_head(skb, 2)) {
36 +               kaweth->stats.tx_errors++;
37 +               netif_start_queue(net);
38 +               spin_unlock_irq(&kaweth->device_lock);
39 +               dev_kfree_skb_any(skb);
40 +               return NETDEV_TX_OK;
41         }
42  
43         private_header = (__le16 *)__skb_push(skb, 2);