Skip to content

Commit e8684db

Browse files
microchip1davem330
authored andcommitted
net: ethernet: microchip: lan743x: Fix skb allocation failure
The driver allocates skb during ndo_open with GFP_ATOMIC which has high chance of failure when there are multiple instances. GFP_KERNEL is enough while open and use GFP_ATOMIC only from interrupt context. Fixes: 23f0703 ("lan743x: Add main source files for new lan743x driver") Signed-off-by: Yuiko Oshino <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1d9d6fd commit e8684db

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/net/ethernet/microchip/lan743x_main.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,8 @@ static void lan743x_rx_update_tail(struct lan743x_rx *rx, int index)
19441944
index);
19451945
}
19461946

1947-
static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index)
1947+
static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index,
1948+
gfp_t gfp)
19481949
{
19491950
struct net_device *netdev = rx->adapter->netdev;
19501951
struct device *dev = &rx->adapter->pdev->dev;
@@ -1958,7 +1959,7 @@ static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index)
19581959

19591960
descriptor = &rx->ring_cpu_ptr[index];
19601961
buffer_info = &rx->buffer_info[index];
1961-
skb = __netdev_alloc_skb(netdev, buffer_length, GFP_ATOMIC | GFP_DMA);
1962+
skb = __netdev_alloc_skb(netdev, buffer_length, gfp);
19621963
if (!skb)
19631964
return -ENOMEM;
19641965
dma_ptr = dma_map_single(dev, skb->data, buffer_length, DMA_FROM_DEVICE);
@@ -2120,7 +2121,8 @@ static int lan743x_rx_process_buffer(struct lan743x_rx *rx)
21202121

21212122
/* save existing skb, allocate new skb and map to dma */
21222123
skb = buffer_info->skb;
2123-
if (lan743x_rx_init_ring_element(rx, rx->last_head)) {
2124+
if (lan743x_rx_init_ring_element(rx, rx->last_head,
2125+
GFP_ATOMIC | GFP_DMA)) {
21242126
/* failed to allocate next skb.
21252127
* Memory is very low.
21262128
* Drop this packet and reuse buffer.
@@ -2335,13 +2337,16 @@ static int lan743x_rx_ring_init(struct lan743x_rx *rx)
23352337

23362338
rx->last_head = 0;
23372339
for (index = 0; index < rx->ring_size; index++) {
2338-
ret = lan743x_rx_init_ring_element(rx, index);
2340+
ret = lan743x_rx_init_ring_element(rx, index, GFP_KERNEL);
23392341
if (ret)
23402342
goto cleanup;
23412343
}
23422344
return 0;
23432345

23442346
cleanup:
2347+
netif_warn(rx->adapter, ifup, rx->adapter->netdev,
2348+
"Error allocating memory for LAN743x\n");
2349+
23452350
lan743x_rx_ring_cleanup(rx);
23462351
return ret;
23472352
}

0 commit comments

Comments
 (0)