Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: mscc: fix the frame extraction into the skb

When extracting frames from the Ocelot switch, the frame check sequence
(FCS) is present at the end of the data extracted. The FCS was put into
the sk buffer which introduced some issues (as length related ones), as
the FCS shouldn't be part of an Rx sk buffer.

This patch fixes the Ocelot switch extraction behaviour by discarding
the FCS.

Fixes: a556c76adc05 ("net: mscc: Add initial Ocelot switch support")
Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Antoine Tenart and committed by
David S. Miller
652ef42c 10bc6a60

+9 -3
+9 -3
drivers/net/ethernet/mscc/ocelot_board.c
··· 91 91 struct sk_buff *skb; 92 92 struct net_device *dev; 93 93 u32 *buf; 94 - int sz, len; 94 + int sz, len, buf_len; 95 95 u32 ifh[4]; 96 96 u32 val; 97 97 struct frame_info info; ··· 116 116 err = -ENOMEM; 117 117 break; 118 118 } 119 - buf = (u32 *)skb_put(skb, info.len); 119 + buf_len = info.len - ETH_FCS_LEN; 120 + buf = (u32 *)skb_put(skb, buf_len); 120 121 121 122 len = 0; 122 123 do { 123 124 sz = ocelot_rx_frame_word(ocelot, grp, false, &val); 124 125 *buf++ = val; 125 126 len += sz; 126 - } while ((sz == 4) && (len < info.len)); 127 + } while (len < buf_len); 128 + 129 + /* Read the FCS and discard it */ 130 + sz = ocelot_rx_frame_word(ocelot, grp, false, &val); 131 + /* Update the statistics if part of the FCS was read before */ 132 + len -= ETH_FCS_LEN - sz; 127 133 128 134 if (sz < 0) { 129 135 err = sz;