Skip to content

Commit 19e72b0

Browse files
Wei Fangkuba-moo
authored andcommitted
net: fec: check the return value of build_skb()
The build_skb might return a null pointer but there is no check on the return value in the fec_enet_rx_queue(). So a null pointer dereference might occur. To avoid this, we check the return value of build_skb. If the return value is a null pointer, the driver will recycle the page and update the statistic of ndev. Then jump to rx_processing_done to clear the status flags of the BD so that the hardware can recycle the BD. Fixes: 95698ff ("net: fec: using page pool to manage RX buffers") Signed-off-by: Wei Fang <[email protected]> Reviewed-by: Shenwei Wang <[email protected]> Reviewed-by: Alexander Duyck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 4be84df commit 19e72b0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/net/ethernet/freescale/fec_main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,14 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id)
16741674
* bridging applications.
16751675
*/
16761676
skb = build_skb(page_address(page), PAGE_SIZE);
1677+
if (unlikely(!skb)) {
1678+
page_pool_recycle_direct(rxq->page_pool, page);
1679+
ndev->stats.rx_dropped++;
1680+
1681+
netdev_err_once(ndev, "build_skb failed!\n");
1682+
goto rx_processing_done;
1683+
}
1684+
16771685
skb_reserve(skb, data_start);
16781686
skb_put(skb, pkt_len - sub_len);
16791687
skb_mark_for_recycle(skb);

0 commit comments

Comments
 (0)