Skip to content

Commit 9eb8bc5

Browse files
LGA1150davem330
authored andcommitted
net: dsa: tag_rtl4_a: fix egress tags
Commit 86dd986 has several issues, but was accepted too soon before anyone could take a look. - Double free. dsa_slave_xmit() will free the skb if the xmit function returns NULL, but the skb is already freed by eth_skb_pad(). Use __skb_put_padto() to avoid that. - Unnecessary allocation. It has been done by DSA core since commit a3b0b64. - A u16 pointer points to skb data. It should be __be16 for network byte order. - Typo in comments. "numer" -> "number". Fixes: 86dd986 ("net: dsa: tag_rtl4_a: Support also egress tags") Signed-off-by: DENG Qingfang <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 826d821 commit 9eb8bc5

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

net/dsa/tag_rtl4_a.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ static struct sk_buff *rtl4a_tag_xmit(struct sk_buff *skb,
3535
struct net_device *dev)
3636
{
3737
struct dsa_port *dp = dsa_slave_to_port(dev);
38+
__be16 *p;
3839
u8 *tag;
39-
u16 *p;
4040
u16 out;
4141

4242
/* Pad out to at least 60 bytes */
43-
if (unlikely(eth_skb_pad(skb)))
44-
return NULL;
45-
if (skb_cow_head(skb, RTL4_A_HDR_LEN) < 0)
43+
if (unlikely(__skb_put_padto(skb, ETH_ZLEN, false)))
4644
return NULL;
4745

4846
netdev_dbg(dev, "add realtek tag to package to port %d\n",
@@ -53,13 +51,13 @@ static struct sk_buff *rtl4a_tag_xmit(struct sk_buff *skb,
5351
tag = skb->data + 2 * ETH_ALEN;
5452

5553
/* Set Ethertype */
56-
p = (u16 *)tag;
54+
p = (__be16 *)tag;
5755
*p = htons(RTL4_A_ETHERTYPE);
5856

5957
out = (RTL4_A_PROTOCOL_RTL8366RB << 12) | (2 << 8);
60-
/* The lower bits is the port numer */
58+
/* The lower bits is the port number */
6159
out |= (u8)dp->index;
62-
p = (u16 *)(tag + 2);
60+
p = (__be16 *)(tag + 2);
6361
*p = htons(out);
6462

6563
return skb;

0 commit comments

Comments
 (0)