Skip to contentSkip to conversation

net: Remove shadow variable in netdev_run_todo()

PATCH Applied Breno Leitao 3 participants 3 messages Feb 21, 2025 – Feb 24, 2025

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

PATCH 1/1 net: Remove shadow variable in netdev_run_todo()

Fix a shadow variable warning in net/core/dev.c when compiled with CONFIG_LOCKDEP enabled. The warning occurs because 'dev' is redeclared inside the while loop, shadowing the outer scope declaration.

net/core/dev.c:11211:22: warning: declaration shadows a local variable [-Wshadow]
struct net_device *dev = list_first_entry(&unlink_list,

net/core/dev.c:11202:21: note: previous declaration is here
struct net_device *dev, *tmp;

Remove the redundant declaration since the variable is already defined in the outer scope and will be overwritten in the subsequent list_for_each_entry_safe() loop anyway.

---
Sending this against net-next and not using "Fixes:" tag since I don't think we want this to be backported to stable tree.

---
 net/core/dev.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
net/core/dev.c +2 -3
index 18064be6cf3e3ae0949722a4ffffdc25fdd16b2e..c36b9b05364bab117ce51f3cc6ea5839245fd182 100644
@@ -11208,9 +11208,8 @@ void netdev_run_todo(void)
 	list_replace_init(&net_unlink_list, &unlink_list);
 
 	while (!list_empty(&unlink_list)) {
-		struct net_device *dev = list_first_entry(&unlink_list,
-							  struct net_device,
-							  unlink_list);
+		dev = list_first_entry(&unlink_list, struct net_device,
+				       unlink_list);
 		list_del_init(&dev->unlink_list);
 		dev->nested_level = dev->lower_level - 1;
 	}

---
base-commit: bb3bb6c92e5719c0f5d7adb9d34db7e76705ac33
change-id: 20250221-netcons_fix_shadow-e2607c682129

Best regards,

Signature · 1 line
Breno Leitao <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Breno Leitao

Fix a shadow variable warning in net/core/dev.c when compiled with CONFIG_LOCKDEP enabled. The warning occurs because 'dev' is redeclared inside the while loop, shadowing the outer scope declaration.

net/core/dev.c:11211:22: warning: declaration shadows a local variable [-Wshadow]
struct net_device *dev = list_first_entry(&unlink_list,

Quoted 8 lines

net/core/dev.c:11202:21: note: previous declaration is here
struct net_device *dev, *tmp;

Remove the redundant declaration since the variable is already defined in the outer scope and will be overwritten in the subsequent list_for_each_entry_safe() loop anyway.

#2 lore raw
In reply to Breno Leitao
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 8 lines · On Fri, 21 Feb 2025 09:51:27 -0800 you wrote:

Fix a shadow variable warning in net/core/dev.c when compiled with CONFIG_LOCKDEP enabled. The warning occurs because 'dev' is redeclared inside the while loop, shadowing the outer scope declaration.

net/core/dev.c:11211:22: warning: declaration shadows a local variable [-Wshadow]
struct net_device *dev = list_first_entry(&unlink_list,

[...]

Here is the summary with links:
- [net-next] net: Remove shadow variable in netdev_run_todo()

    https://git.kernel.org/netdev/net-next/c/7183877d6853

You are awesome, thank you!

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