Subject: Re: [RFC PATCH net-next v2 7/9] bnxt: add helpers for allocating rx ring mem

From: Simon Horman <[email-masked]>
Date: Sat, 4 May 2024 13:34:32 +0100

On Wed, May 01, 2024 at 09:54:08PM -0700, David Wei wrote:
> Add several helper functions for allocating rx ring memory. These are
> mostly taken from existing functions, but with unnecessary bits stripped
> out such that only allocations are done.
> 
> Signed-off-by: David Wei <[email-masked]>
> ---
>  drivers/net/ethernet/broadcom/bnxt/bnxt.c | 87 +++++++++++++++++++++++
>  1 file changed, 87 insertions(+)
> 
> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> index b0a8d14b7319..21c1a7cb70ab 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> @@ -14845,6 +14845,93 @@ static const struct netdev_stat_ops bnxt_stat_ops = {
>  	.get_base_stats		= bnxt_get_base_stats,
>  };
>  
> +static int __bnxt_alloc_rx_desc_ring(struct pci_dev *pdev, struct bnxt_ring_mem_info *rmem)
> +{
> +	int i, rc;
> +
> +	for (i = 0; i < rmem->nr_pages; i++) {
> +		rmem->pg_arr[i] = dma_alloc_coherent(&pdev->dev,
> +						     rmem->page_size,
> +						     &rmem->dma_arr[i],
> +						     GFP_KERNEL);
> +		if (!rmem->pg_arr[i]) {
> +			rc = -ENOMEM;
> +			goto err_free;
> +		}
> +	}
> +
> +	return 0;
> +
> +err_free:
> +	while (i--) {
> +		dma_free_coherent(&pdev->dev, rmem->page_size,
> +				  rmem->pg_arr[i], rmem->dma_arr[i]);
> +		rmem->pg_arr[i] = NULL;
> +	}
> +	return rc;
> +}
> +
> +static int bnxt_alloc_rx_ring_struct(struct bnxt *bp, struct bnxt_ring_struct *ring)

Hi David,

W=1 builds fail because this and other functions introduced by
this patch are unused. I agree that it is nice to split up changes
into discrete patches. But in this case the change isn't really discrete.
So perhaps it is best to add helper functions in the same patch
where they are first used.