Skip to contentSkip to conversation

btrfs: Remove redundant assignment of slot and leaf

PATCH In review Jiapeng Chong 2 participants 2 messages Jan 5, 2022 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 btrfs: Remove redundant assignment of slot and leaf

From: chongjiapeng <[email protected]>

slot and leaf are being initialized to path->slots[0] and path->nodes[0], but this is never read as slot and leaf is overwritten later on. Remove the redundant assignment.

Cleans up the following clang-analyzer warning:

fs/btrfs/tree-log.c:6125:7: warning: Value stored to 'slot' during its initialization is never read [clang-analyzer-deadcode.DeadStores].

---
Changes in v2:
-Remove redundant assignment of leaf.

 fs/btrfs/tree-log.c | 2 --
 1 file changed, 2 deletions(-)
fs/btrfs/tree-log.c +0 -2
index 4b89ac769347..d99cda0acd95 100644
@@ -6188,8 +6188,6 @@ static int log_new_ancestors(struct btrfs_trans_handle *trans,
 		if (ret < 0)
 			return ret;
 
-		leaf = path->nodes[0];
-		slot = path->slots[0];
 		if (slot >= btrfs_header_nritems(leaf)) {
 			ret = btrfs_next_leaf(root, path);
 			if (ret < 0)
Signature · 1 line
2.19.1.6.gb485710b
#1 lore raw
Quoted 25 lines · Jiapeng Chong

From: chongjiapeng <[email protected]>

slot and leaf are being initialized to path->slots[0] and path->nodes[0], but this is never read as slot and leaf is overwritten later on. Remove the redundant assignment.

Cleans up the following clang-analyzer warning:

fs/btrfs/tree-log.c:6125:7: warning: Value stored to 'slot' during its initialization is never read [clang-analyzer-deadcode.DeadStores].

---
Changes in v2:
-Remove redundant assignment of leaf.

 fs/btrfs/tree-log.c | 2 --
 1 file changed, 2 deletions(-)
fs/btrfs/tree-log.c +0 -0
index 4b89ac769347..d99cda0acd95 100644

fs/btrfs/tree-log.c static int log_new_ancestors(struct btrfs_trans_handle *trans, · line 6192

Quoted 5 lines
fs/btrfs/tree-log.c +0 -2
@@ -6188,8 +6188,6 @@ static int log_new_ancestors(struct btrfs_trans_handle *trans,
 		if (ret < 0)
 			return ret;
 
-		leaf = path->nodes[0];
-		slot = path->slots[0];

No, this is not correct.

Right before those assignments we called btrfs_search_slot(), which updates path->nodes and path->slots, and we need those updated values below.

The redundant assignments are not these two, but instead the ones when the variables are declared at the top of the loop:

   struct extent_buffer *leaf = path->nodes[0];
   int slot = path->slots[0];

Thanks.

Quoted 6 lines
fs/btrfs/tree-log.c +0 -0
 		if (slot >= btrfs_header_nritems(leaf)) {
 			ret = btrfs_next_leaf(root, path);
 			if (ret < 0)
Signature · 1 line
2.19.1.6.gb485710b