btrfs: remove shadowed declaration of variable i in for-loops
Subsystems (2)
PATCH 1/1 btrfs: remove shadowed declaration of variable i in for-loops
The variable i is declared at the start of function btrfs_qgroup_inherit however there are two for-loops that redeclare the variable using a C99 declaration, causes name shadowing. I believe there is no need for this local scoping of i in the loop, so replace the declaration in the loops with assignments.
Cleans up clang scan build warnings:
fs/btrfs/qgroup.c:3194:12: warning: declaration shadows a local variable [-Wshadow]
3194 | for (int i = 0; i < inherit->num_qgroups; i++) {
| ^fs/btrfs/qgroup.c:3089:6: note: previous declaration is here
3089 | int i;
| ^fs/btrfs/qgroup.c:3321:12: warning: declaration shadows a local variable [-Wshadow]
3321 | for (int i = 0; i < inherit->num_qgroups; i++)
| ^fs/btrfs/qgroup.c:3089:6: note: previous declaration is here
3089 | int i;
| ^
--- fs/btrfs/qgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/qgroup.c +2 -2
@@ -3191,7 +3191,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid, ret = -ENOMEM ; goto out; } -for (int i =0 ; i < inherit->num_qgroups; i++) { +for (i =0 ; i < inherit->num_qgroups; i++) { qlist_prealloc[i] =kzalloc (sizeof (struct btrfs_qgroup_list ),GFP_NOFS );if (!qlist_prealloc[i]) {
@@ -3318,7 +3318,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,if (need_rescan)qgroup_mark_inconsistent (fs_info);if (qlist_prealloc) { -for (int i =0 ; i < inherit->num_qgroups; i++) +for (i =0 ; i < inherit->num_qgroups; i++)kfree (qlist_prealloc[i]);kfree (qlist_prealloc); }
Signature · 1 line
2.39.2
Quoted 31 lines · Colin Ian King
The variable i is declared at the start of function
btrfs_qgroup_inherithowever there are two for-loops that redeclare the variable using a C99 declaration, causes name shadowing. I believe there is no need for this local scoping of i in the loop, so replace the declaration in the loops with assignments.Cleans up clang scan build warnings:
fs/btrfs/qgroup.c:3194:12: warning: declaration shadows a local variable [-Wshadow]
3194 | for (int i = 0; i <inherit->num_qgroups; i++) {
| ^fs/btrfs/qgroup.c:3089:6: note: previous declaration is here
3089 | int i;
| ^fs/btrfs/qgroup.c:3321:12: warning: declaration shadows a local variable [-Wshadow]
3321 | for (int i = 0; i <inherit->num_qgroups; i++)
| ^fs/btrfs/qgroup.c:3089:6: note: previous declaration is here
3089 | int i;
| ^Signed-off-by Colin Ian King <[email protected]>--- fs/btrfs/qgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/btrfs/qgroup.c +0
-0
fs/btrfs/qgroup.c int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid, · line 3194
Quoted 5 lines
fs/btrfs/qgroup.c +1
-1@@ -3191,7 +3191,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid, ret = -ENOMEM ; goto out; } -for (int i =0 ; i < inherit->num_qgroups; i++) { +for (i =0 ; i < inherit->num_qgroups; i++) {
We want to use the for(...) local definitions, so this should change the function scope 'i'.