diff mbox series

[net-next,v2] net: Remove redundant variable declaration in __dev_change_flags()

Message ID 20250217-old_flags-v2-1-4cda3b43a35f@debian.org (mailing list archive)
State Accepted
Commit 8f02c48f8f623eedc3c0a26a64c7ef155c35bfb9
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v2] net: Remove redundant variable declaration in __dev_change_flags() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 1 this patch: 1
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5 this patch: 5
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 79 this patch: 79
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-18--00-00 (tests: 891)

Commit Message

Breno Leitao Feb. 17, 2025, 3:48 p.m. UTC
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.

Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Mateusz Polchlopek <mateusz.polchlopek@intel.com>
---
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/20250214-old_flags-v1-1-29096b9399a9@debian.org
---
 net/core/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


---
base-commit: 7a7e0197133d18cfd9931e7d3a842d0f5730223f
change-id: 20250214-old_flags-528fe052471c

Best regards,

Comments

Kalesh Anakkur Purayil Feb. 18, 2025, 2:55 a.m. UTC | #1
On Mon, Feb 17, 2025 at 9:21 PM Breno Leitao <leitao@debian.org> wrote:
>
> 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.
>
> Signed-off-by: Breno Leitao <leitao@debian.org>
> Reviewed-by: Mateusz Polchlopek <mateusz.polchlopek@intel.com>

LGTM,
Reviewed-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Nicolas Dichtel Feb. 18, 2025, 8:35 a.m. UTC | #2
Le 17/02/2025 à 16:48, Breno Leitao a écrit :
> 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.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>
> Reviewed-by: Mateusz Polchlopek <mateusz.polchlopek@intel.com>
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Andrew Lunn Feb. 18, 2025, 1:53 p.m. UTC | #3
On Tue, Feb 18, 2025 at 09:35:55AM +0100, Nicolas Dichtel wrote:
> Le 17/02/2025 à 16:48, Breno Leitao a écrit :
> > 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.
> > 
> > Signed-off-by: Breno Leitao <leitao@debian.org>
> > Reviewed-by: Mateusz Polchlopek <mateusz.polchlopek@intel.com>
> Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
patchwork-bot+netdevbpf@kernel.org Feb. 19, 2025, 2:20 a.m. UTC | #4
Hello:

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

On Mon, 17 Feb 2025 07:48:13 -0800 you wrote:
> 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.
> 
> [...]

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!
diff mbox series

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index d5ab9a4b318ea4926c200ef20dae01eaafa18c6b..cd2474a138201e6ee86acf39ca425d57d8d2e9b4 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -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;