diff mbox series

[net] net: mvpp2: Don't re-use loop iterator

Message ID eaa8f403-7779-4d81-973d-a9ecddc0bf6f@stanley.mountain (mailing list archive)
State Accepted
Commit 0aa3ca956c46d849775eae1816cef8fe4bc8b50e
Delegated to: Netdev Maintainers
Headers show
Series [net] net: mvpp2: Don't re-use loop iterator | 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: 273 this patch: 273
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 281 this patch: 281
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: 338 this patch: 338
netdev/checkpatch warning WARNING: line length of 87 exceeds 80 columns
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-07-26--15-00 (tests: 707)

Commit Message

Dan Carpenter July 24, 2024, 4:06 p.m. UTC
This function has a nested loop.  The problem is that both the inside
and outside loop use the same variable as an iterator.  I found this
via static analysis so I'm not sure the impact.  It could be that it
loops forever or, more likely, the loop exits early.

Fixes: 3a616b92a9d1 ("net: mvpp2: Add TX flow control support for jumbo frames")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Simon Horman July 24, 2024, 6:50 p.m. UTC | #1
On Wed, Jul 24, 2024 at 11:06:56AM -0500, Dan Carpenter wrote:
> This function has a nested loop.  The problem is that both the inside
> and outside loop use the same variable as an iterator.  I found this
> via static analysis so I'm not sure the impact.  It could be that it
> loops forever or, more likely, the loop exits early.
> 
> Fixes: 3a616b92a9d1 ("net: mvpp2: Add TX flow control support for jumbo frames")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Simon Horman <horms@kernel.org>
Jakub Kicinski July 25, 2024, 3:04 p.m. UTC | #2
On Wed, 24 Jul 2024 11:06:56 -0500 Dan Carpenter wrote:
> This function has a nested loop.  The problem is that both the inside
> and outside loop use the same variable as an iterator.  I found this
> via static analysis so I'm not sure the impact.  It could be that it
> loops forever or, more likely, the loop exits early.

> diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
> index 8c45ad983abc..0d62a33afa80 100644
> --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
> +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
> @@ -953,13 +953,13 @@ static void mvpp2_bm_pool_update_fc(struct mvpp2_port *port,
>  static void mvpp2_bm_pool_update_priv_fc(struct mvpp2 *priv, bool en)
>  {
>  	struct mvpp2_port *port;
> -	int i;
> +	int i, j;
>  
>  	for (i = 0; i < priv->port_count; i++) {
>  		port = priv->port_list[i];
>  		if (port->priv->percpu_pools) {
> -			for (i = 0; i < port->nrxqs; i++)
> -				mvpp2_bm_pool_update_fc(port, &port->priv->bm_pools[i],
> +			for (j = 0; j < port->nrxqs; j++)
> +				mvpp2_bm_pool_update_fc(port, &port->priv->bm_pools[j],
>  							port->tx_fc & en);
>  		} else {
>  			mvpp2_bm_pool_update_fc(port, port->pool_long, port->tx_fc & en);

Stefan, can you comment? priv->bm_pools are global (not per port)
AFAICT, so this may be semi-intentional.
patchwork-bot+netdevbpf@kernel.org July 30, 2024, 4:20 p.m. UTC | #3
Hello:

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

On Wed, 24 Jul 2024 11:06:56 -0500 you wrote:
> This function has a nested loop.  The problem is that both the inside
> and outside loop use the same variable as an iterator.  I found this
> via static analysis so I'm not sure the impact.  It could be that it
> loops forever or, more likely, the loop exits early.
> 
> Fixes: 3a616b92a9d1 ("net: mvpp2: Add TX flow control support for jumbo frames")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> 
> [...]

Here is the summary with links:
  - [net] net: mvpp2: Don't re-use loop iterator
    https://git.kernel.org/netdev/net/c/0aa3ca956c46

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 8c45ad983abc..0d62a33afa80 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -953,13 +953,13 @@  static void mvpp2_bm_pool_update_fc(struct mvpp2_port *port,
 static void mvpp2_bm_pool_update_priv_fc(struct mvpp2 *priv, bool en)
 {
 	struct mvpp2_port *port;
-	int i;
+	int i, j;
 
 	for (i = 0; i < priv->port_count; i++) {
 		port = priv->port_list[i];
 		if (port->priv->percpu_pools) {
-			for (i = 0; i < port->nrxqs; i++)
-				mvpp2_bm_pool_update_fc(port, &port->priv->bm_pools[i],
+			for (j = 0; j < port->nrxqs; j++)
+				mvpp2_bm_pool_update_fc(port, &port->priv->bm_pools[j],
 							port->tx_fc & en);
 		} else {
 			mvpp2_bm_pool_update_fc(port, port->pool_long, port->tx_fc & en);