Skip to contentSkip to conversation

dpaa2-switch: Fix error checking in dpaa2_switch_seed_bp()

PATCH Applied Dan Carpenter 4 participants 4 messages Aug 17, 2024 – Aug 20, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dpaa2-switch: Fix error checking in dpaa2_switch_seed_bp()

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")

---
From reviewing the code. Not tested.

---
 drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c +4 -3
index a71f848adc05..a293b08f36d4 100644
@@ -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;
 	}
 
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Dan Carpenter

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.

Quoted 6 lines

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

Fixes 0b1b71370458 ("staging: dpaa2-switch: handle Rx path on control interface")

---

Quoted 1 line

From reviewing the code. Not tested.

maintainer Reviewed-by Tested-by on v1 1/1
#2 lore raw
In reply to Dan Carpenter
Quoted 8 lines · Dan Carpenter

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.

Quoted 4 lines

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

Fixes 0b1b71370458 ("staging: dpaa2-switch: handle Rx path on control interface")

Thanks,
Ioana

#3 lore raw
In reply to Dan Carpenter
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 9 lines · 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!

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