diff mbox series

[RFC,net-next,v2,5/9] bnxt: refactor bnxt_{alloc,free}_one_tpa_info()

Message ID 20240502045410.3524155-6-dw@davidwei.uk (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series bnxt: implement queue api | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 926 this patch: 926
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 937 this patch: 937
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 939 this patch: 939
netdev/checkpatch fail CHECK: Alignment should match open parenthesis ERROR: space required before the open parenthesis '(' WARNING: line length of 84 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 2 this patch: 2
netdev/source_inline success Was 0 now: 0

Commit Message

David Wei May 2, 2024, 4:54 a.m. UTC
Refactor the allocation of each rx ring's tpa_info in
bnxt_alloc_tpa_info() out into a standalone function
__bnxt_alloc_one_tpa_info().

In case of allocation failures during bnxt_alloc_tpa_info(), clean up
in-place.

Change bnxt_free_tpa_info() to free a single rx ring passed in as a
parameter. This makes bnxt_free_rx_rings() more symmetrical.

Signed-off-by: David Wei <dw@davidwei.uk>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 95 +++++++++++++++--------
 1 file changed, 62 insertions(+), 33 deletions(-)

Comments

Simon Horman May 4, 2024, 12:30 p.m. UTC | #1
On Wed, May 01, 2024 at 09:54:06PM -0700, David Wei wrote:
> Refactor the allocation of each rx ring's tpa_info in
> bnxt_alloc_tpa_info() out into a standalone function
> __bnxt_alloc_one_tpa_info().
> 
> In case of allocation failures during bnxt_alloc_tpa_info(), clean up
> in-place.
> 
> Change bnxt_free_tpa_info() to free a single rx ring passed in as a
> parameter. This makes bnxt_free_rx_rings() more symmetrical.
> 
> Signed-off-by: David Wei <dw@davidwei.uk>

Hi David,

Some minor nits flagged by

./scripts/checkpatch.pl --codespell --max-line-length=80 --strict

> ---
>  drivers/net/ethernet/broadcom/bnxt/bnxt.c | 95 +++++++++++++++--------
>  1 file changed, 62 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c

...

> +static int __bnxt_alloc_one_tpa_info(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
> +{

Please consider limiting Networking code to 80 columns wide where
it can be trivially achieved.

In this case, perhaps:

static int __bnxt_alloc_one_tpa_info(struct bnxt *bp,
				     struct bnxt_rx_ring_info *rxr)

> +	struct rx_agg_cmp *agg;
> +	int i, rc;
> +
> +	rxr->rx_tpa = kcalloc(bp->max_tpa, sizeof(struct bnxt_tpa_info),
> +				GFP_KERNEL);

The indentation here is not quite right.

	rxr->rx_tpa = kcalloc(bp->max_tpa, sizeof(struct bnxt_tpa_info),
			      GFP_KERNEL);

> +	if (!rxr->rx_tpa)
> +		return -ENOMEM;
> +
> +	if (!(bp->flags & BNXT_FLAG_CHIP_P5_PLUS))
> +		return 0;
> +
> +	for (i = 0; i < bp->max_tpa; i++) {
> +		agg = kcalloc(MAX_SKB_FRAGS, sizeof(*agg), GFP_KERNEL);
> +		if (!agg) {
> +			rc = -ENOMEM;
> +			goto err_free;
>  		}
> -		kfree(rxr->rx_tpa);
> -		rxr->rx_tpa = NULL;
> +		rxr->rx_tpa[i].agg_arr = agg;
> +	}
> +	rxr->rx_tpa_idx_map = kzalloc(sizeof(*rxr->rx_tpa_idx_map),
> +					GFP_KERNEL);
> +	if (!rxr->rx_tpa_idx_map) {
> +		rc = -ENOMEM;
> +		goto err_free;
>  	}
> +
> +	return 0;
> +
> +err_free:
> +	while(i--) {

Space before '(' here please.

> +		kfree(rxr->rx_tpa[i].agg_arr);
> +		rxr->rx_tpa[i].agg_arr = NULL;
> +	}
> +	kfree(rxr->rx_tpa);
> +	rxr->rx_tpa = NULL;
> +
> +	return rc;
>  }

...
David Wei May 6, 2024, 12:43 a.m. UTC | #2
On 2024-05-04 05:30, Simon Horman wrote:
> On Wed, May 01, 2024 at 09:54:06PM -0700, David Wei wrote:
>> Refactor the allocation of each rx ring's tpa_info in
>> bnxt_alloc_tpa_info() out into a standalone function
>> __bnxt_alloc_one_tpa_info().
>>
>> In case of allocation failures during bnxt_alloc_tpa_info(), clean up
>> in-place.
>>
>> Change bnxt_free_tpa_info() to free a single rx ring passed in as a
>> parameter. This makes bnxt_free_rx_rings() more symmetrical.
>>
>> Signed-off-by: David Wei <dw@davidwei.uk>
> 
> Hi David,
> 
> Some minor nits flagged by
> 
> ./scripts/checkpatch.pl --codespell --max-line-length=80 --strict

I didn't run through the usual checks because this is an RFC. I'll fix
it for the next series, thanks.

> 
>> ---
>>  drivers/net/ethernet/broadcom/bnxt/bnxt.c | 95 +++++++++++++++--------
>>  1 file changed, 62 insertions(+), 33 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> 
> ...
> 
>> +static int __bnxt_alloc_one_tpa_info(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
>> +{
> 
> Please consider limiting Networking code to 80 columns wide where
> it can be trivially achieved.
> 
> In this case, perhaps:
> 
> static int __bnxt_alloc_one_tpa_info(struct bnxt *bp,
> 				     struct bnxt_rx_ring_info *rxr)
> 
>> +	struct rx_agg_cmp *agg;
>> +	int i, rc;
>> +
>> +	rxr->rx_tpa = kcalloc(bp->max_tpa, sizeof(struct bnxt_tpa_info),
>> +				GFP_KERNEL);
> 
> The indentation here is not quite right.
> 
> 	rxr->rx_tpa = kcalloc(bp->max_tpa, sizeof(struct bnxt_tpa_info),
> 			      GFP_KERNEL);
> 
>> +	if (!rxr->rx_tpa)
>> +		return -ENOMEM;
>> +
>> +	if (!(bp->flags & BNXT_FLAG_CHIP_P5_PLUS))
>> +		return 0;
>> +
>> +	for (i = 0; i < bp->max_tpa; i++) {
>> +		agg = kcalloc(MAX_SKB_FRAGS, sizeof(*agg), GFP_KERNEL);
>> +		if (!agg) {
>> +			rc = -ENOMEM;
>> +			goto err_free;
>>  		}
>> -		kfree(rxr->rx_tpa);
>> -		rxr->rx_tpa = NULL;
>> +		rxr->rx_tpa[i].agg_arr = agg;
>> +	}
>> +	rxr->rx_tpa_idx_map = kzalloc(sizeof(*rxr->rx_tpa_idx_map),
>> +					GFP_KERNEL);
>> +	if (!rxr->rx_tpa_idx_map) {
>> +		rc = -ENOMEM;
>> +		goto err_free;
>>  	}
>> +
>> +	return 0;
>> +
>> +err_free:
>> +	while(i--) {
> 
> Space before '(' here please.
> 
>> +		kfree(rxr->rx_tpa[i].agg_arr);
>> +		rxr->rx_tpa[i].agg_arr = NULL;
>> +	}
>> +	kfree(rxr->rx_tpa);
>> +	rxr->rx_tpa = NULL;
>> +
>> +	return rc;
>>  }
> 
> ...
diff mbox series

Patch

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 7b20303f3b7d..bda49e7f6c3d 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -3500,29 +3500,66 @@  static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem)
 	return 0;
 }
 
-static void bnxt_free_tpa_info(struct bnxt *bp)
+static void bnxt_free_tpa_info(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
 {
-	int i, j;
+	int i;
 
-	for (i = 0; i < bp->rx_nr_rings; i++) {
-		struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
+	kfree(rxr->rx_tpa_idx_map);
+	rxr->rx_tpa_idx_map = NULL;
+	if (rxr->rx_tpa) {
+		for (i = 0; i < bp->max_tpa; i++) {
+			kfree(rxr->rx_tpa[i].agg_arr);
+			rxr->rx_tpa[i].agg_arr = NULL;
+		}
+	}
+	kfree(rxr->rx_tpa);
+	rxr->rx_tpa = NULL;
+}
 
-		kfree(rxr->rx_tpa_idx_map);
-		rxr->rx_tpa_idx_map = NULL;
-		if (rxr->rx_tpa) {
-			for (j = 0; j < bp->max_tpa; j++) {
-				kfree(rxr->rx_tpa[j].agg_arr);
-				rxr->rx_tpa[j].agg_arr = NULL;
-			}
+static int __bnxt_alloc_one_tpa_info(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
+{
+	struct rx_agg_cmp *agg;
+	int i, rc;
+
+	rxr->rx_tpa = kcalloc(bp->max_tpa, sizeof(struct bnxt_tpa_info),
+				GFP_KERNEL);
+	if (!rxr->rx_tpa)
+		return -ENOMEM;
+
+	if (!(bp->flags & BNXT_FLAG_CHIP_P5_PLUS))
+		return 0;
+
+	for (i = 0; i < bp->max_tpa; i++) {
+		agg = kcalloc(MAX_SKB_FRAGS, sizeof(*agg), GFP_KERNEL);
+		if (!agg) {
+			rc = -ENOMEM;
+			goto err_free;
 		}
-		kfree(rxr->rx_tpa);
-		rxr->rx_tpa = NULL;
+		rxr->rx_tpa[i].agg_arr = agg;
+	}
+	rxr->rx_tpa_idx_map = kzalloc(sizeof(*rxr->rx_tpa_idx_map),
+					GFP_KERNEL);
+	if (!rxr->rx_tpa_idx_map) {
+		rc = -ENOMEM;
+		goto err_free;
 	}
+
+	return 0;
+
+err_free:
+	while(i--) {
+		kfree(rxr->rx_tpa[i].agg_arr);
+		rxr->rx_tpa[i].agg_arr = NULL;
+	}
+	kfree(rxr->rx_tpa);
+	rxr->rx_tpa = NULL;
+
+	return rc;
 }
 
 static int bnxt_alloc_tpa_info(struct bnxt *bp)
 {
-	int i, j;
+	int i, rc;
 
 	bp->max_tpa = MAX_TPA;
 	if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) {
@@ -3533,27 +3570,18 @@  static int bnxt_alloc_tpa_info(struct bnxt *bp)
 
 	for (i = 0; i < bp->rx_nr_rings; i++) {
 		struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
-		struct rx_agg_cmp *agg;
-
-		rxr->rx_tpa = kcalloc(bp->max_tpa, sizeof(struct bnxt_tpa_info),
-				      GFP_KERNEL);
-		if (!rxr->rx_tpa)
-			return -ENOMEM;
 
-		if (!(bp->flags & BNXT_FLAG_CHIP_P5_PLUS))
-			continue;
-		for (j = 0; j < bp->max_tpa; j++) {
-			agg = kcalloc(MAX_SKB_FRAGS, sizeof(*agg), GFP_KERNEL);
-			if (!agg)
-				return -ENOMEM;
-			rxr->rx_tpa[j].agg_arr = agg;
-		}
-		rxr->rx_tpa_idx_map = kzalloc(sizeof(*rxr->rx_tpa_idx_map),
-					      GFP_KERNEL);
-		if (!rxr->rx_tpa_idx_map)
-			return -ENOMEM;
+		rc = __bnxt_alloc_one_tpa_info(bp, rxr);
+		if (rc)
+			goto err_free;
 	}
 	return 0;
+
+err_free:
+	while (i--)
+		bnxt_free_tpa_info(bp, &bp->rx_ring[i]);
+
+	return rc;
 }
 
 static void bnxt_free_rx_rings(struct bnxt *bp)
@@ -3563,11 +3591,12 @@  static void bnxt_free_rx_rings(struct bnxt *bp)
 	if (!bp->rx_ring)
 		return;
 
-	bnxt_free_tpa_info(bp);
 	for (i = 0; i < bp->rx_nr_rings; i++) {
 		struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
 		struct bnxt_ring_struct *ring;
 
+		bnxt_free_tpa_info(bp, rxr);
+
 		if (rxr->xdp_prog)
 			bpf_prog_put(rxr->xdp_prog);