netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] dpaa2-switch: Fix error checking in dpaa2_switch_seed_bp()
@ 2024-08-17  6:52 Dan Carpenter
  2024-08-19  9:30 ` Simon Horman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dan Carpenter @ 2024-08-17  6:52 UTC (permalink / raw)
  To: Ioana Ciornei
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Vladimir Oltean, netdev, linux-kernel, kernel-janitors

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

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;
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] dpaa2-switch: Fix error checking in dpaa2_switch_seed_bp()
  2024-08-17  6:52 [PATCH net] dpaa2-switch: Fix error checking in dpaa2_switch_seed_bp() Dan Carpenter
@ 2024-08-19  9:30 ` Simon Horman
  2024-08-20 12:33 ` Ioana Ciornei
  2024-08-20 22:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2024-08-19  9:30 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Ioana Ciornei, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Vladimir Oltean, netdev, linux-kernel,
	kernel-janitors

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>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] dpaa2-switch: Fix error checking in dpaa2_switch_seed_bp()
  2024-08-17  6:52 [PATCH net] dpaa2-switch: Fix error checking in dpaa2_switch_seed_bp() Dan Carpenter
  2024-08-19  9:30 ` Simon Horman
@ 2024-08-20 12:33 ` Ioana Ciornei
  2024-08-20 22:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Ioana Ciornei @ 2024-08-20 12:33 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Vladimir Oltean, netdev, linux-kernel, kernel-janitors

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] dpaa2-switch: Fix error checking in dpaa2_switch_seed_bp()
  2024-08-17  6:52 [PATCH net] dpaa2-switch: Fix error checking in dpaa2_switch_seed_bp() Dan Carpenter
  2024-08-19  9:30 ` Simon Horman
  2024-08-20 12:33 ` Ioana Ciornei
@ 2024-08-20 22:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-08-20 22:30 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: ioana.ciornei, davem, edumazet, kuba, pabeni, vladimir.oltean,
	netdev, linux-kernel, kernel-janitors

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-20 22:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-17  6:52 [PATCH net] dpaa2-switch: Fix error checking in dpaa2_switch_seed_bp() Dan Carpenter
2024-08-19  9:30 ` Simon Horman
2024-08-20 12:33 ` Ioana Ciornei
2024-08-20 22:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).