net: Remove redundant variable declaration in __dev_change_flags()
Subsystems (2)
PATCH v2 1/1 net: Remove redundant variable declaration in __dev_change_flags()
The old_flags variable is declared twice in __dev_change_flags(), causing a shadow variable warning. This patch fixes the issue by removing the redundant declaration, reusing the existing old_flags variable instead.
net/core/dev.c:9225:16: warning: declaration shadows a local variable [-Wshadow]
9225 | unsigned int old_flags = dev->flags;
| ^
net/core/dev.c:9185:15: note: previous declaration is here
9185 | unsigned int old_flags = dev->flags;
| ^
1 warning generated.
Remove the redundant inner declaration and reuse the existing old_flags variable since its value is not needed outside the if block, and it is safe to reuse the variable. This eliminates the warning while maintaining the same functionality.
---
Changes in v2:
- Improve the commit message to specify that there is no impact reusing the variable (Andrew)
- Remove the Fixes tag, since we do not want this to be backported. (Andrew)
- Link to v1: https://lore.kernel.org/r/[email protected]
--- net/core/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
@@ -9182,7 +9182,7 @@ int __dev_change_flags(struct net_device *dev, unsigned int flags,if ((flags ^ dev->gflags) &IFF_PROMISC ) {int inc = (flags &IFF_PROMISC ) ?1 :-1 ; -unsigned int old_flags = dev->flags; + old_flags = dev->flags; dev->gflags ^=IFF_PROMISC ;
---
base-commit: 7a7e0197133d18cfd9931e7d3a842d0f5730223f
change-id: 20250214-old_flags-528fe052471c
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
Quoted 14 lines · Breno Leitao
The
old_flagsvariable is declared twice in__dev_change_flags(), causing a shadow variable warning. This patch fixes the issue by removing the redundant declaration, reusing the existingold_flagsvariable instead.
net/core/dev.c:9225:16: warning: declaration shadows a local variable [-Wshadow]
9225 | unsigned intold_flags=dev->flags;
| ^
net/core/dev.c:9185:15: note: previous declaration is here
9185 | unsigned intold_flags=dev->flags;
| ^
1 warning generated.
Quoted 7 lines
Remove the redundant inner declaration and reuse the existing
old_flagsvariable since its value is not needed outside the if block, and it is safe to reuse the variable. This eliminates the warning while maintaining the same functionality.Signed-off-by Breno Leitao <[email protected]>Reviewed-by Mateusz Polchlopek <[email protected]>
LGTM,
Signature · 2 lines
Regards, Kalesh AP
Le 17/02/2025 à 16:48, Breno Leitao a écrit :
Quoted 13 lines
The
old_flagsvariable is declared twice in__dev_change_flags(), causing a shadow variable warning. This patch fixes the issue by removing the redundant declaration, reusing the existingold_flagsvariable instead.
net/core/dev.c:9225:16: warning: declaration shadows a local variable [-Wshadow]
9225 | unsigned intold_flags=dev->flags;
| ^
net/core/dev.c:9185:15: note: previous declaration is here
9185 | unsigned intold_flags=dev->flags;
| ^
1 warning generated.
Quoted 7 lines
Remove the redundant inner declaration and reuse the existing
old_flagsvariable since its value is not needed outside the if block, and it is safe to reuse the variable. This eliminates the warning while maintaining the same functionality.Signed-off-by Breno Leitao <[email protected]>Reviewed-by Mateusz Polchlopek <[email protected]>
Andrew Lunn
Reviewed-byQuoted 14 lines · Nicolas Dichtel
Le 17/02/2025 à 16:48, Breno Leitao a écrit :
Quoted 13 lines
The
old_flagsvariable is declared twice in__dev_change_flags(), causing a shadow variable warning. This patch fixes the issue by removing the redundant declaration, reusing the existingold_flagsvariable instead.
net/core/dev.c:9225:16: warning: declaration shadows a local variable [-Wshadow]
9225 | unsigned intold_flags=dev->flags;
| ^
net/core/dev.c:9185:15: note: previous declaration is here
9185 | unsigned intold_flags=dev->flags;
| ^
1 warning generated.
Quoted 8 lines
Quoted 7 lines
Remove the redundant inner declaration and reuse the existing
old_flagsvariable since its value is not needed outside the if block, and it is safe to reuse the variable. This eliminates the warning while maintaining the same functionality.Signed-off-by Breno Leitao <[email protected]>Reviewed-by Mateusz Polchlopek <[email protected]>Reviewed-by Nicolas Dichtel <[email protected]>
Andrew
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 13 lines · On Mon, 17 Feb 2025 07:48:13 -0800 you wrote:
The
old_flagsvariable is declared twice in__dev_change_flags(), causing a shadow variable warning. This patch fixes the issue by removing the redundant declaration, reusing the existingold_flagsvariable instead.
net/core/dev.c:9225:16: warning: declaration shadows a local variable [-Wshadow]
9225 | unsigned intold_flags=dev->flags;
| ^
net/core/dev.c:9185:15: note: previous declaration is here
9185 | unsigned intold_flags=dev->flags;
| ^
1 warning generated.
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,v2] net: Remove redundant variable declaration in __dev_change_flags()
https://git.kernel.org/netdev/net-next/c/8f02c48f8f62
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html