Skip to content

Commit

Permalink
net: dsa: factor skb freeing on xmit
Browse files Browse the repository at this point in the history
The taggers are currently responsible to free the original SKB if they
made a copy of it, or in case of error.

This patch simplifies this by freeing the original SKB in the
dsa_slave_xmit caller, but only if an error (NULL) is returned.

It is still the responsibility of the tagger to free the original SKB if
it returned a copy of it.

At the same time, fix the checkpatch NULL comparison check:

        CHECK: Comparison to NULL could be written "!nskb"
    torvalds#208: FILE: net/dsa/tag_trailer.c:35:
    +	if (nskb == NULL)

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
  • Loading branch information
vivien authored and 0day robot committed May 31, 2017
1 parent 1e8bd88 commit c5f0f73
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 36 deletions.
8 changes: 6 additions & 2 deletions net/dsa/slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,14 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
dev->stats.tx_packets++;
dev->stats.tx_bytes += skb->len;

/* Transmit function may have to reallocate the original SKB */
/* Transmit function may have to reallocate the original SKB,
* in which case it must have freed it. Only free it here on error.
*/
nskb = p->xmit(skb, dev);
if (!nskb)
if (!nskb) {
kfree_skb(skb);
return NETDEV_TX_OK;
}

/* SKB for netpoll still need to be mangled with the protocol-specific
* tag to be successfully transmitted
Expand Down
6 changes: 1 addition & 5 deletions net/dsa/tag_brcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev
u8 *brcm_tag;

if (skb_cow_head(skb, BRCM_TAG_LEN) < 0)
goto out_free;
return NULL;

skb_push(skb, BRCM_TAG_LEN);

Expand All @@ -86,10 +86,6 @@ static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev
brcm_tag[3] = (1 << p->dp->index) & BRCM_IG_DSTMAP1_MASK;

return skb;

out_free:
kfree_skb(skb);
return NULL;
}

static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev)
Expand Down
8 changes: 2 additions & 6 deletions net/dsa/tag_dsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev)
*/
if (skb->protocol == htons(ETH_P_8021Q)) {
if (skb_cow_head(skb, 0) < 0)
goto out_free;
return NULL;

/*
* Construct tagged FROM_CPU DSA tag from 802.1q tag.
Expand All @@ -46,7 +46,7 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev)
}
} else {
if (skb_cow_head(skb, DSA_HLEN) < 0)
goto out_free;
return NULL;
skb_push(skb, DSA_HLEN);

memmove(skb->data, skb->data + DSA_HLEN, 2 * ETH_ALEN);
Expand All @@ -62,10 +62,6 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev)
}

return skb;

out_free:
kfree_skb(skb);
return NULL;
}

static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev)
Expand Down
8 changes: 2 additions & 6 deletions net/dsa/tag_edsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev)
*/
if (skb->protocol == htons(ETH_P_8021Q)) {
if (skb_cow_head(skb, DSA_HLEN) < 0)
goto out_free;
return NULL;
skb_push(skb, DSA_HLEN);

memmove(skb->data, skb->data + DSA_HLEN, 2 * ETH_ALEN);
Expand All @@ -55,7 +55,7 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev)
}
} else {
if (skb_cow_head(skb, EDSA_HLEN) < 0)
goto out_free;
return NULL;
skb_push(skb, EDSA_HLEN);

memmove(skb->data, skb->data + EDSA_HLEN, 2 * ETH_ALEN);
Expand All @@ -75,10 +75,6 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev)
}

return skb;

out_free:
kfree_skb(skb);
return NULL;
}

static struct sk_buff *edsa_rcv(struct sk_buff *skb, struct net_device *dev)
Expand Down
5 changes: 1 addition & 4 deletions net/dsa/tag_lan9303.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev)
if (skb_cow_head(skb, LAN9303_TAG_LEN) < 0) {
dev_dbg(&dev->dev,
"Cannot make room for the special tag. Dropping packet\n");
goto out_free;
return NULL;
}

/* provide 'LAN9303_TAG_LEN' bytes additional space */
Expand All @@ -66,9 +66,6 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev)
lan9303_tag[1] = htons(p->dp->index | BIT(4));

return skb;
out_free:
kfree_skb(skb);
return NULL;
}

static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev)
Expand Down
6 changes: 1 addition & 5 deletions net/dsa/tag_mtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
u8 *mtk_tag;

if (skb_cow_head(skb, MTK_HDR_LEN) < 0)
goto out_free;
return NULL;

skb_push(skb, MTK_HDR_LEN);

Expand All @@ -41,10 +41,6 @@ static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
mtk_tag[3] = 0;

return skb;

out_free:
kfree_skb(skb);
return NULL;
}

static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev)
Expand Down
6 changes: 1 addition & 5 deletions net/dsa/tag_qca.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
dev->stats.tx_bytes += skb->len;

if (skb_cow_head(skb, 0) < 0)
goto out_free;
return NULL;

skb_push(skb, QCA_HDR_LEN);

Expand All @@ -60,10 +60,6 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
*phdr = htons(hdr);

return skb;

out_free:
kfree_skb(skb);
return NULL;
}

static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
Expand Down
4 changes: 1 addition & 3 deletions net/dsa/tag_trailer.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev)
padlen = 60 - skb->len;

nskb = alloc_skb(NET_IP_ALIGN + skb->len + padlen + 4, GFP_ATOMIC);
if (nskb == NULL) {
kfree_skb(skb);
if (!nskb)
return NULL;
}
skb_reserve(nskb, NET_IP_ALIGN);

skb_reset_mac_header(nskb);
Expand Down

0 comments on commit c5f0f73

Please sign in to comment.