Skip to content

Commit

Permalink
Merge branch 'skb_cow_head'
Browse files Browse the repository at this point in the history
Eric Dumazet says:

====================
net: use skb_cow_head() to deal with cloned skbs

James Hughes found an issue with smsc95xx driver. Same problematic code
is found in other drivers.
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Apr 21, 2017
2 parents 95b9b88 + 39fba78 commit 918b702
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 44 deletions.
9 changes: 2 additions & 7 deletions drivers/net/usb/ch9200.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,9 @@ static struct sk_buff *ch9200_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
tx_overhead = 0x40;

len = skb->len;
if (skb_headroom(skb) < tx_overhead) {
struct sk_buff *skb2;

skb2 = skb_copy_expand(skb, tx_overhead, 0, flags);
if (skb_cow_head(skb, tx_overhead)) {
dev_kfree_skb_any(skb);
skb = skb2;
if (!skb)
return NULL;
return NULL;
}

__skb_push(skb, tx_overhead);
Expand Down
7 changes: 2 additions & 5 deletions drivers/net/usb/cx82310_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,9 @@ static struct sk_buff *cx82310_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
{
int len = skb->len;

if (skb_headroom(skb) < 2) {
struct sk_buff *skb2 = skb_copy_expand(skb, 2, 0, flags);
if (skb_cow_head(skb, 2)) {
dev_kfree_skb_any(skb);
skb = skb2;
if (!skb)
return NULL;
return NULL;
}
skb_push(skb, 2);

Expand Down
18 changes: 6 additions & 12 deletions drivers/net/usb/kaweth.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,18 +803,12 @@ static netdev_tx_t kaweth_start_xmit(struct sk_buff *skb,
}

/* We now decide whether we can put our special header into the sk_buff */
if (skb_cloned(skb) || skb_headroom(skb) < 2) {
/* no such luck - we make our own */
struct sk_buff *copied_skb;
copied_skb = skb_copy_expand(skb, 2, 0, GFP_ATOMIC);
dev_kfree_skb_irq(skb);
skb = copied_skb;
if (!copied_skb) {
kaweth->stats.tx_errors++;
netif_start_queue(net);
spin_unlock_irq(&kaweth->device_lock);
return NETDEV_TX_OK;
}
if (skb_cow_head(skb, 2)) {
kaweth->stats.tx_errors++;
netif_start_queue(net);
spin_unlock_irq(&kaweth->device_lock);
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
}

private_header = (__le16 *)__skb_push(skb, 2);
Expand Down
9 changes: 2 additions & 7 deletions drivers/net/usb/lan78xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2607,14 +2607,9 @@ static struct sk_buff *lan78xx_tx_prep(struct lan78xx_net *dev,
{
u32 tx_cmd_a, tx_cmd_b;

if (skb_headroom(skb) < TX_OVERHEAD) {
struct sk_buff *skb2;

skb2 = skb_copy_expand(skb, TX_OVERHEAD, 0, flags);
if (skb_cow_head(skb, TX_OVERHEAD)) {
dev_kfree_skb_any(skb);
skb = skb2;
if (!skb)
return NULL;
return NULL;
}

if (lan78xx_linearize(skb) < 0)
Expand Down
8 changes: 2 additions & 6 deletions drivers/net/usb/smsc75xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2203,13 +2203,9 @@ static struct sk_buff *smsc75xx_tx_fixup(struct usbnet *dev,
{
u32 tx_cmd_a, tx_cmd_b;

if (skb_headroom(skb) < SMSC75XX_TX_OVERHEAD) {
struct sk_buff *skb2 =
skb_copy_expand(skb, SMSC75XX_TX_OVERHEAD, 0, flags);
if (skb_cow_head(skb, SMSC75XX_TX_OVERHEAD)) {
dev_kfree_skb_any(skb);
skb = skb2;
if (!skb)
return NULL;
return NULL;
}

tx_cmd_a = (u32)(skb->len & TX_CMD_A_LEN) | TX_CMD_A_FCS;
Expand Down
9 changes: 2 additions & 7 deletions drivers/net/usb/sr9700.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,9 @@ static struct sk_buff *sr9700_tx_fixup(struct usbnet *dev, struct sk_buff *skb,

len = skb->len;

if (skb_headroom(skb) < SR_TX_OVERHEAD) {
struct sk_buff *skb2;

skb2 = skb_copy_expand(skb, SR_TX_OVERHEAD, 0, flags);
if (skb_cow_head(skb, SR_TX_OVERHEAD)) {
dev_kfree_skb_any(skb);
skb = skb2;
if (!skb)
return NULL;
return NULL;
}

__skb_push(skb, SR_TX_OVERHEAD);
Expand Down

0 comments on commit 918b702

Please sign in to comment.