Skip to content

Commit d903ec7

Browse files
aspencer-spacexdavem330
authored andcommitted
gianfar: simplify FCS handling and fix memory leak
Previously, buffer descriptors containing only the frame check sequence (FCS) were skipped and not added to the skb. However, the page reference count was still incremented, leading to a memory leak. Fixing this inside gfar_add_rx_frag() is difficult due to reserved memory handling and page reuse. Instead, move the FCS handling to gfar_process_frame() and trim off the FCS before passing the skb up the networking stack. Signed-off-by: Andy Spencer <aspencer@spacex.com> Signed-off-by: Jim Gruen <jgruen@spacex.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ca79bec commit d903ec7

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

drivers/net/ethernet/freescale/gianfar.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,29 +2934,17 @@ static bool gfar_add_rx_frag(struct gfar_rx_buff *rxb, u32 lstatus,
29342934
{
29352935
int size = lstatus & BD_LENGTH_MASK;
29362936
struct page *page = rxb->page;
2937-
bool last = !!(lstatus & BD_LFLAG(RXBD_LAST));
2938-
2939-
/* Remove the FCS from the packet length */
2940-
if (last)
2941-
size -= ETH_FCS_LEN;
29422937

29432938
if (likely(first)) {
29442939
skb_put(skb, size);
29452940
} else {
29462941
/* the last fragments' length contains the full frame length */
2947-
if (last)
2942+
if (lstatus & BD_LFLAG(RXBD_LAST))
29482943
size -= skb->len;
29492944

2950-
/* Add the last fragment if it contains something other than
2951-
* the FCS, otherwise drop it and trim off any part of the FCS
2952-
* that was already received.
2953-
*/
2954-
if (size > 0)
2955-
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
2956-
rxb->page_offset + RXBUF_ALIGNMENT,
2957-
size, GFAR_RXB_TRUESIZE);
2958-
else if (size < 0)
2959-
pskb_trim(skb, skb->len + size);
2945+
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
2946+
rxb->page_offset + RXBUF_ALIGNMENT,
2947+
size, GFAR_RXB_TRUESIZE);
29602948
}
29612949

29622950
/* try reuse page */
@@ -3069,6 +3057,9 @@ static void gfar_process_frame(struct net_device *ndev, struct sk_buff *skb)
30693057
if (priv->padding)
30703058
skb_pull(skb, priv->padding);
30713059

3060+
/* Trim off the FCS */
3061+
pskb_trim(skb, skb->len - ETH_FCS_LEN);
3062+
30723063
if (ndev->features & NETIF_F_RXCSUM)
30733064
gfar_rx_checksum(skb, fcb);
30743065

0 commit comments

Comments
 (0)