bcachefs: remove redundant initialization of variable level
PATCH 1/1 bcachefs: remove redundant initialization of variable level
Variable level is being initialized a value that is never read, the variable is being re-assigned another value several statements later on. The initialization is redundant and can be removed. Cleans up clang scan build warning:
fs/bcachefs/btree_iter.c:1217:11: warning: Value stored to 'level' during its initialization is never read [deadcode.DeadStores]
--- fs/bcachefs/btree_iter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/bcachefs/btree_iter.c +1 -1
@@ -1214,7 +1214,7 @@ __bch2_btree_path_set_pos(struct btree_trans *trans, struct btree_path *path, struct bpos new_pos, bool intent, unsigned long ip, int cmp) { - unsigned level = path->level; + unsigned level;bch2_trans_verify_not_in_restart (trans);EBUG_ON (!path->ref);
Signature · 1 line
2.39.2
Quoted 9 lines · Colin Ian King
Variable level is being initialized a value that is never read, the variable is being re-assigned another value several statements later on. The initialization is redundant and can be removed. Cleans up clang scan build warning:
fs/bcachefs/btree_iter.c:1217:11: warning: Value stored to 'level' during its initialization is never read [deadcode.DeadStores]Signed-off-by Colin Ian King <[email protected]>
since we're no longer gnu89, we can simply declare the variable when it's first used, like so:
fs/bcachefs/btree_iter.c +1 -3
@@ -1214,8 +1214,6 @@ __bch2_btree_path_set_pos(struct btree_trans *trans, struct btree_path *path, struct bpos new_pos, bool intent, unsigned long ip, int cmp) { - unsigned level = path->level; -bch2_trans_verify_not_in_restart (trans );EBUG_ON (!path->ref);
@@ -1231,7 +1229,7 @@ __bch2_btree_path_set_pos(struct btree_trans *trans, goto out; } - level =btree_path_up_until_good_node (trans, path, cmp); +unsigned level =btree_path_up_until_good_node (trans, path, cmp);if (btree_path_node (path, level)) {struct btree_path_level *l = &path->l[level];
From: Kent Overstreet <[email protected]>
Quoted 6 lines
Sent: 11 November 2023 21:02
Quoted 5 lines
Variable level is being initialized a value that is never read, the variable is being re-assigned another value several statements later on. The initialization is redundant and can be removed. Cleans up clang scan build warning:
Quoted 7 lines
Quoted 4 lines
fs/bcachefs/btree_iter.c:1217:11: warning: Value stored to 'level' during its initialization is never read [deadcode.DeadStores]Signed-off-by Colin Ian King <[email protected]>since we're no longer gnu89, we can simply declare the variable when it's first used, like so:
ugg... I think that is still frowned upon.
It makes it very difficult for the average human to find the variable declaration.
David
Quoted 15 lines
fs/bcachefs/btree_iter.c +0
-2@@ -1214,8 +1214,6 @@ __bch2_btree_path_set_pos(struct btree_trans *trans, struct btree_path *path, struct bpos new_pos, bool intent, unsigned long ip, int cmp) { - unsigned level = path->level; -bch2_trans_verify_not_in_restart (trans );EBUG_ON (!path->ref);
fs/bcachefs/btree_iter.c __bch2_btree_path_set_pos(struct btree_trans *trans, · line 1235
Quoted 8 lines
fs/bcachefs/btree_iter.c +1
-1@@ -1231,7 +1229,7 @@ __bch2_btree_path_set_pos(struct btree_trans *trans, goto out; } - level =btree_path_up_until_good_node (trans, path, cmp); +unsigned level =btree_path_up_until_good_node (trans, path, cmp);if (btree_path_node (path, level)) {struct btree_path_level *l = &path->l[level];
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 10 lines · David Laight
From: Kent Overstreet <[email protected]>
Quoted 9 lines
Sent: 11 November 2023 21:02
Quoted 8 lines
Variable level is being initialized a value that is never read, the variable is being re-assigned another value several statements later on. The initialization is redundant and can be removed. Cleans up clang scan build warning:
fs/bcachefs/btree_iter.c:1217:11: warning: Value stored to 'level' during its initialization is never read [deadcode.DeadStores]
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Colin Ian King <[email protected]>since we're no longer gnu89, we can simply declare the variable when it's first used, like so:
ugg... I think that is still frowned upon.
It makes it very difficult for the average human to find the variable declaration.
No, it's 2023, there's no good reason to be declaring variables before giving them values.
From: Kent Overstreet
Quoted 18 lines
Sent: 11 November 2023 23:39
Quoted 15 lines · David Laight
From: Kent Overstreet <[email protected]>
Quoted 13 lines
Sent: 11 November 2023 21:02
Quoted 9 lines
Variable level is being initialized a value that is never read, the variable is being re-assigned another value several statements later on. The initialization is redundant and can be removed. Cleans up clang scan build warning:
fs/bcachefs/btree_iter.c:1217:11: warning: Value stored to 'level' during its initialization is never read [deadcode.DeadStores]Signed-off-by Colin Ian King <[email protected]>since we're no longer gnu89, we can simply declare the variable when it's first used, like so:
Quoted 6 lines
Quoted 3 lines
ugg... I think that is still frowned upon.
It makes it very difficult for the average human to find the variable declaration.No, it's 2023, there's no good reason to be declaring variables before giving them values.
The year has nothing to do with whether it is a good idea. It is epically bad without -Wshadow.
(Have you ever played 'stop the declaration' in C++, it isn't fun.)
Finding declarations is bad enough when they are at the top of a big block, never mind in the middle of a load of assignments.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 26 lines · David Laight
From: Kent Overstreet
Quoted 18 lines
Sent: 11 November 2023 23:39
Quoted 15 lines · David Laight
From: Kent Overstreet <[email protected]>
Quoted 13 lines
Sent: 11 November 2023 21:02
Quoted 9 lines
Variable level is being initialized a value that is never read, the variable is being re-assigned another value several statements later on. The initialization is redundant and can be removed. Cleans up clang scan build warning:
fs/bcachefs/btree_iter.c:1217:11: warning: Value stored to 'level' during its initialization is never read [deadcode.DeadStores]Signed-off-by Colin Ian King <[email protected]>since we're no longer gnu89, we can simply declare the variable when it's first used, like so:
Quoted 6 lines
Quoted 3 lines
ugg... I think that is still frowned upon.
It makes it very difficult for the average human to find the variable declaration.No, it's 2023, there's no good reason to be declaring variables before giving them values.
Quoted 6 lines
The year has nothing to do with whether it is a good idea. It is epically bad without -Wshadow.
(Have you ever played 'stop the declaration' in C++, it isn't fun.)Finding declarations is bad enough when they are at the top of a big block, never mind in the middle of a load of assignments.
David, I don't want you giving this kind of advice here, and if finding declarations is something you have trouble with - perhaps find something easier to do.
Quoted 3 lines · Kent Overstreet
David, I don't want you giving this kind of advice here, and if finding declarations is something you have trouble with - perhaps find something easier to do.
David is correct. Putting declarations in the middle of code is still frowned on. It's necessary for the __cleanup work and it's okay in for loop iterators but it's generally frowned on.
Please don't force people to redo patches in non-standard style.
regards,
dan carpenter