diff mbox series

[net] net: bcmasp: Handle RX buffer allocation failure

Message ID 20240213173339.3438713-1-florian.fainelli@broadcom.com (mailing list archive)
State Accepted
Commit e5b2e810daf9f2d87fe132eb4d2a85fb08a0db98
Delegated to: Netdev Maintainers
Headers show
Series [net] net: bcmasp: Handle RX buffer allocation failure | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 976 this patch: 976
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 993 this patch: 993
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 993 this patch: 993
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 15 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-15--00-00 (tests: 1443)

Commit Message

Florian Fainelli Feb. 13, 2024, 5:33 p.m. UTC
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")
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Justin Chen Feb. 13, 2024, 6:56 p.m. UTC | #1
On 2/13/24 9:33 AM, Florian Fainelli 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.
> 
> Fixes: 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller")
> Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>

Reviewed-by: Justin Chen <justin.chen@broadcom.com>

> ---
>   drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
> index 53e542881255..f59557b0cd51 100644
> --- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
> +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
> @@ -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)
patchwork-bot+netdevbpf@kernel.org Feb. 15, 2024, 12:40 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

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!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
index 53e542881255..f59557b0cd51 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c
@@ -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)