diff mbox series

[net] dpaa2-switch: Fix error checking in dpaa2_switch_seed_bp()

Message ID eec27f30-b43f-42b6-b8ee-04a6f83423b6@stanley.mountain (mailing list archive)
State Accepted
Commit c50e7475961c36ec4d21d60af055b32f9436b431
Delegated to: Netdev Maintainers
Headers show
Series [net] dpaa2-switch: Fix error checking in dpaa2_switch_seed_bp() | 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: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
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: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 17 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-08-20--09-00 (tests: 712)

Commit Message

Dan Carpenter Aug. 17, 2024, 6:52 a.m. UTC
The dpaa2_switch_add_bufs() function returns the number of bufs that it
was able to add.  It returns BUFS_PER_CMD (7) for complete success or a
smaller number if there are not enough pages available.  However, the
error checking is looking at the total number of bufs instead of the
number which were added on this iteration.  Thus the error checking
only works correctly for the first iteration through the loop and
subsequent iterations are always counted as a success.

Fix this by checking only the bufs added in the current iteration.

Fixes: 0b1b71370458 ("staging: dpaa2-switch: handle Rx path on control interface")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
From reviewing the code.  Not tested.
---
 drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Simon Horman Aug. 19, 2024, 9:30 a.m. UTC | #1
On Sat, Aug 17, 2024 at 09:52:46AM +0300, Dan Carpenter wrote:
> The dpaa2_switch_add_bufs() function returns the number of bufs that it
> was able to add.  It returns BUFS_PER_CMD (7) for complete success or a
> smaller number if there are not enough pages available.  However, the
> error checking is looking at the total number of bufs instead of the
> number which were added on this iteration.  Thus the error checking
> only works correctly for the first iteration through the loop and
> subsequent iterations are always counted as a success.
> 
> Fix this by checking only the bufs added in the current iteration.
> 
> Fixes: 0b1b71370458 ("staging: dpaa2-switch: handle Rx path on control interface")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> >From reviewing the code.  Not tested.

Reviewed-by: Simon Horman <horms@kernel.org>
Ioana Ciornei Aug. 20, 2024, 12:33 p.m. UTC | #2
On Sat, Aug 17, 2024 at 09:52:46AM +0300, Dan Carpenter wrote:
> The dpaa2_switch_add_bufs() function returns the number of bufs that it
> was able to add.  It returns BUFS_PER_CMD (7) for complete success or a
> smaller number if there are not enough pages available.  However, the
> error checking is looking at the total number of bufs instead of the
> number which were added on this iteration.  Thus the error checking
> only works correctly for the first iteration through the loop and
> subsequent iterations are always counted as a success.
> 
> Fix this by checking only the bufs added in the current iteration.
> 
> Fixes: 0b1b71370458 ("staging: dpaa2-switch: handle Rx path on control interface")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Tested-by: Ioana Ciornei <ioana.ciornei@nxp.com>

Thanks,
Ioana
patchwork-bot+netdevbpf@kernel.org Aug. 20, 2024, 10:30 p.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Sat, 17 Aug 2024 09:52:46 +0300 you wrote:
> The dpaa2_switch_add_bufs() function returns the number of bufs that it
> was able to add.  It returns BUFS_PER_CMD (7) for complete success or a
> smaller number if there are not enough pages available.  However, the
> error checking is looking at the total number of bufs instead of the
> number which were added on this iteration.  Thus the error checking
> only works correctly for the first iteration through the loop and
> subsequent iterations are always counted as a success.
> 
> [...]

Here is the summary with links:
  - [net] dpaa2-switch: Fix error checking in dpaa2_switch_seed_bp()
    https://git.kernel.org/netdev/net/c/c50e7475961c

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c
index a71f848adc05..a293b08f36d4 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c
@@ -2638,13 +2638,14 @@  static int dpaa2_switch_refill_bp(struct ethsw_core *ethsw)
 
 static int dpaa2_switch_seed_bp(struct ethsw_core *ethsw)
 {
-	int *count, i;
+	int *count, ret, i;
 
 	for (i = 0; i < DPAA2_ETHSW_NUM_BUFS; i += BUFS_PER_CMD) {
+		ret = dpaa2_switch_add_bufs(ethsw, ethsw->bpid);
 		count = &ethsw->buf_count;
-		*count += dpaa2_switch_add_bufs(ethsw, ethsw->bpid);
+		*count += ret;
 
-		if (unlikely(*count < BUFS_PER_CMD))
+		if (unlikely(ret < BUFS_PER_CMD))
 			return -ENOMEM;
 	}