Skip to contentSkip to conversation

net: bcmasp: Handle RX buffer allocation failure

PATCH Applied Florian Fainelli 3 participants 3 messages Feb 13, 2024 – Feb 15, 2024

Subsystems (3)
lore
Share & tools
lore

Florian Fainelli

author maintainer
#0 lore raw

PATCH 1/1 net: bcmasp: Handle RX buffer allocation failure

The buffer_pg variable needs to hold an order-5 allocation (32 x PAGE_SIZE) which, under memory pressure may fail to be allocated. Deal with that error condition properly to avoid doing a NULL pointer de-reference in the subsequent call to dma_map_page().

In addition, the err_reclaim_tx error label in bcmasp_netif_init() needs to ensure that the TX NAPI object is properly deleted, otherwise unregister_netdev() will spin forever attempting to test and clear the NAPI_STATE_HASHED bit.

Fixes 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller")
---
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +3 -0
index 53e542881255..f59557b0cd51 100644
@@ -684,6 +684,8 @@ static int bcmasp_init_rx(struct bcmasp_intf *intf)
 
 	intf->rx_buf_order = get_order(RING_BUFFER_SIZE);
 	buffer_pg = alloc_pages(GFP_KERNEL, intf->rx_buf_order);
+	if (!buffer_pg)
+		return -ENOMEM;
 
 	dma = dma_map_page(kdev, buffer_pg, 0, RING_BUFFER_SIZE,
 			   DMA_FROM_DEVICE);
@@ -1092,6 +1094,7 @@ static int bcmasp_netif_init(struct net_device *dev, bool phy_connect)
 	return 0;
 
 err_reclaim_tx:
+	netif_napi_del(&intf->tx_napi);
 	bcmasp_reclaim_free_all_tx(intf);
 err_phy_disconnect:
 	if (phydev)
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Florian Fainelli

The buffer_pg variable needs to hold an order-5 allocation (32 x PAGE_SIZE) which, under memory pressure may fail to be allocated. Deal with that error condition properly to avoid doing a NULL pointer de-reference in the subsequent call to dma_map_page().

Quoted 7 lines

In addition, the err_reclaim_tx error label in bcmasp_netif_init() needs to ensure that the TX NAPI object is properly deleted, otherwise unregister_netdev() will spin forever attempting to test and clear the NAPI_STATE_HASHED bit.

Fixes 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller")
Quoted 25 lines
---
  drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +3 -0
index 53e542881255..f59557b0cd51 100644
@@ -684,6 +684,8 @@ static int bcmasp_init_rx(struct bcmasp_intf *intf)
 
  	intf->rx_buf_order = get_order(RING_BUFFER_SIZE);
  	buffer_pg = alloc_pages(GFP_KERNEL, intf->rx_buf_order);
+	if (!buffer_pg)
+		return -ENOMEM;
 
  	dma = dma_map_page(kdev, buffer_pg, 0, RING_BUFFER_SIZE,
  			   DMA_FROM_DEVICE);
@@ -1092,6 +1094,7 @@ static int bcmasp_netif_init(struct net_device *dev, bool phy_connect)
  	return 0;
 
  err_reclaim_tx:
+	netif_napi_del(&intf->tx_napi);
  	bcmasp_reclaim_free_all_tx(intf);
  err_phy_disconnect:
  	if (phydev)
#2 lore raw
In reply to Florian Fainelli
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 11 lines · On Tue, 13 Feb 2024 09:33:39 -0800 you wrote:

The buffer_pg variable needs to hold an order-5 allocation (32 x PAGE_SIZE) which, under memory pressure may fail to be allocated. Deal with that error condition properly to avoid doing a NULL pointer de-reference in the subsequent call to dma_map_page().

In addition, the err_reclaim_tx error label in bcmasp_netif_init() needs to ensure that the TX NAPI object is properly deleted, otherwise unregister_netdev() will spin forever attempting to test and clear the NAPI_STATE_HASHED bit.

[...]

Here is the summary with links:
- [net] net: bcmasp: Handle RX buffer allocation failure

    https://git.kernel.org/netdev/net/c/e5b2e810daf9

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html