Skip to contentSkip to conversation

bcachefs: clean up some redundant assignments

PATCH In review Colin Ian King 3 participants 9 messages Sep 12, 2023 Kernel janitors

lore
Share & tools
lore
#0 lore raw

cover bcachefs: clean up some redundant assignments

Clean up some redundant assignments and variables based on warnings found by clang scan build static analysis.

Colin Ian King (5):
bcachefs: remove redundant initialization of pointer d
bcachefs: remove redundant initialization of pointer dst
bcachefs: remove redundant initializations of variables start_offset
and end_offset
bcachefs: remove duplicated assignment to variable offset_into_extent
bcachefs: remove redundant pointer q

 fs/bcachefs/btree_update_interior.c | 2 +-
 fs/bcachefs/buckets.c               | 2 +-
 fs/bcachefs/disk_groups.c           | 3 +--
 fs/bcachefs/fs-io.c                 | 4 ++--
 fs/bcachefs/io.c                    | 1 -
 fs/bcachefs/quota.c                 | 3 ---
 6 files changed, 5 insertions(+), 10 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/5 bcachefs: remove redundant initialization of pointer d

The pointer d is being initialized with a value that is never read, it is being re-assigned later on when it is used in a for-loop. The initialization is redundant and can be removed.

Cleans up clang-scan build warning:
fs/bcachefs/buckets.c:1303:25: warning: Value stored to 'd' during its initialization is never read [deadcode.DeadStores]

---
 fs/bcachefs/btree_update_interior.c | 2 +-
 fs/bcachefs/buckets.c               | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
fs/bcachefs/btree_update_interior.c +1 -1
index 73c950d2788e..35f7af297ac0 100644
@@ -143,7 +143,7 @@ static size_t btree_node_u64s_with_format(struct btree *b,
 }
 
 /**
- * btree_node_format_fits - check if we could rewrite node with a new format
+ * bch2_btree_node_format_fits - check if we could rewrite node with a new format
  *
  * This assumes all keys can pack with the new format -- it just checks if
  * the re-packed keys would fit inside the node itself.
fs/bcachefs/buckets.c +1 -1
index c02c8c917a29..951f945bbc22 100644
@@ -1300,7 +1300,7 @@ int bch2_trans_fs_usage_apply(struct btree_trans *trans,
 	static int warned_disk_usage = 0;
 	bool warn = false;
 	unsigned disk_res_sectors = trans->disk_res ? trans->disk_res->sectors : 0;
-	struct replicas_delta *d = deltas->d, *d2;
+	struct replicas_delta *d, *d2;
 	struct replicas_delta *top = (void *) deltas->d + deltas->used;
 	struct bch_fs_usage *dst;
 	s64 added = 0, should_not_have_added;
Signature · 1 line
2.39.2
#2 lore raw

PATCH 2/5 bcachefs: remove redundant initialization of pointer dst

In reply to Colin Ian King

The pointer dst is being initialized with a value that is never read, it is being re-assigned later on when it is used in a while-loop The initialization is redundant and can be removed.

Cleans up clang-scan build warning:
fs/bcachefs/disk_groups.c:186:30: warning: Value stored to 'dst' during its initialization is never read [deadcode.DeadStores]

---
 fs/bcachefs/disk_groups.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/bcachefs/disk_groups.c +1 -2
index f36472c4a781..9fa8d7d49f3e 100644
@@ -183,8 +183,7 @@ int bch2_sb_disk_groups_to_cpu(struct bch_fs *c)
 
 	for (i = 0; i < c->disk_sb.sb->nr_devices; i++) {
 		struct bch_member *m = mi->members + i;
-		struct bch_disk_group_cpu *dst =
-			&cpu_g->entries[BCH_MEMBER_GROUP(m)];
+		struct bch_disk_group_cpu *dst;
 
 		if (!bch2_member_exists(m))
 			continue;
Signature · 1 line
2.39.2
#4 lore raw

PATCH 3/5 bcachefs: remove redundant initializations of variables start_offset and end_offset

In reply to Colin Ian King

The variables start_offset and end_offset are being initialized with values that are never read, they being re-assigned later on. The initializations are redundant and can be removed.

Cleans up clang-scan build warnings:
fs/bcachefs/fs-io.c:243:11: warning: Value stored to 'start_offset' during its initialization is never read [deadcode.DeadStores] fs/bcachefs/fs-io.c:244:11: warning: Value stored to 'end_offset' during its initialization is never read [deadcode.DeadStores]

---
 fs/bcachefs/fs-io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/bcachefs/fs-io.c +2 -2
index ceab12fb8a8f..c108335e0502 100644
@@ -240,8 +240,8 @@ static int __bch2_truncate_folio(struct bch_inode_info *inode,
 	struct bch_fs *c = inode->v.i_sb->s_fs_info;
 	struct address_space *mapping = inode->v.i_mapping;
 	struct bch_folio *s;
-	unsigned start_offset = start & (PAGE_SIZE - 1);
-	unsigned end_offset = ((end - 1) & (PAGE_SIZE - 1)) + 1;
+	unsigned start_offset;
+	unsigned end_offset;
 	unsigned i;
 	struct folio *folio;
 	s64 i_sectors_delta = 0;
Signature · 1 line
2.39.2
#5 lore raw

PATCH 4/5 bcachefs: remove duplicated assignment to variable offset_into_extent

In reply to Colin Ian King

Variable offset_into_extent is being assigned to zero and a few statements later it is being re-assigned again to the save value. The second assignment is redundant and can be removed. Cleans up clang-scan build warning:

fs/bcachefs/io.c:2722:3: warning: Value stored to 'offset_into_extent' is never read [deadcode.DeadStores]

---
 fs/bcachefs/io.c | 1 -
 1 file changed, 1 deletion(-)
fs/bcachefs/io.c +0 -1
index 3c614c864b6e..3b827c8dbf12 100644
@@ -2724,7 +2724,6 @@ int __bch2_read_extent(struct btree_trans *trans, struct bch_read_bio *orig,
 		pick.crc.uncompressed_size	= bvec_iter_sectors(iter);
 		pick.crc.offset			= 0;
 		pick.crc.live_size		= bvec_iter_sectors(iter);
-		offset_into_extent		= 0;
 	}
 get_bio:
 	if (rbio) {
Signature · 1 line
2.39.2
#6 lore raw

PATCH 5/5 bcachefs: remove redundant pointer q

In reply to Colin Ian King

The pointer q is being assigned a value but it is never read. The assignment and pointer are redundant and can be removed. Cleans up clang scan build warning:

fs/bcachefs/quota.c:813:2: warning: Value stored to 'q' is never read [deadcode.DeadStores]

---
 fs/bcachefs/quota.c | 3 ---
 1 file changed, 3 deletions(-)
fs/bcachefs/quota.c +0 -3
index ca99772aedc6..719c4c9fc51f 100644
@@ -786,7 +786,6 @@ static int bch2_quota_set_info(struct super_block *sb, int type,
 {
 	struct bch_fs *c = sb->s_fs_info;
 	struct bch_sb_field_quota *sb_quota;
-	struct bch_memquota_type *q;
 	int ret = 0;
 
 	if (0) {
@@ -810,8 +809,6 @@ static int bch2_quota_set_info(struct super_block *sb, int type,
 	    ~(QC_SPC_TIMER|QC_INO_TIMER|QC_SPC_WARNS|QC_INO_WARNS))
 		return -EINVAL;
 
-	q = &c->quotas[type];
-
 	mutex_lock(&c->sb_lock);
 	sb_quota = bch2_sb_get_or_create_quota(&c->disk_sb);
 	if (!sb_quota) {
Signature · 1 line
2.39.2
#3 lore raw

Re: [PATCH 2/5][next] bcachefs: remove redundant initialization of pointer dst

In reply to Colin Ian King
Quoted 18 lines · Colin Ian King

The pointer dst is being initialized with a value that is never read, it is being re-assigned later on when it is used in a while-loop The initialization is redundant and can be removed.

Cleans up clang-scan build warning:
fs/bcachefs/disk_groups.c:186:30: warning: Value stored to 'dst' during its initialization is never read [deadcode.DeadStores]

---
 fs/bcachefs/disk_groups.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/bcachefs/disk_groups.c +0 -0
index f36472c4a781..9fa8d7d49f3e 100644

fs/bcachefs/disk_groups.c int bch2_sb_disk_groups_to_cpu(struct bch_fs *c) · line 186

Quoted 6 lines
fs/bcachefs/disk_groups.c +1 -2
@@ -183,8 +183,7 @@ int bch2_sb_disk_groups_to_cpu(struct bch_fs *c)
 
 	for (i = 0; i < c->disk_sb.sb->nr_devices; i++) {
 		struct bch_member *m = mi->members + i;
-		struct bch_disk_group_cpu *dst =
-			&cpu_g->entries[BCH_MEMBER_GROUP(m)];
+		struct bch_disk_group_cpu *dst;

Nit: kind of seems like this variable could just be lifted to the top of the function given that it's used in two loops, but the patch seems fine to me either way.

Brian

Quoted 6 lines
fs/bcachefs/disk_groups.c +0 -0
 		if (!bch2_member_exists(m))
 			continue;
Signature · 1 line
2.39.2
Reviewed-by on the v1 series
#7 lore raw
In reply to Colin Ian King
Quoted 3 lines · Colin Ian King

Clean up some redundant assignments and variables based on warnings found by clang scan build static analysis.

These all look good to me. For the series:

Quoted 19 lines

Colin Ian King (5):
bcachefs: remove redundant initialization of pointer d
bcachefs: remove redundant initialization of pointer dst
bcachefs: remove redundant initializations of variables start_offset
and end_offset
bcachefs: remove duplicated assignment to variable offset_into_extent
bcachefs: remove redundant pointer q

 fs/bcachefs/btree_update_interior.c | 2 +-
 fs/bcachefs/buckets.c               | 2 +-
 fs/bcachefs/disk_groups.c           | 3 +--
 fs/bcachefs/fs-io.c                 | 4 ++--
 fs/bcachefs/io.c                    | 1 -
 fs/bcachefs/quota.c                 | 3 ---
 6 files changed, 5 insertions(+), 10 deletions(-)
Signature · 1 line
2.39.2
#8 lore raw
In reply to Colin Ian King
Quoted 11 lines · Colin Ian King

Clean up some redundant assignments and variables based on warnings found by clang scan build static analysis.

Colin Ian King (5):
bcachefs: remove redundant initialization of pointer d
bcachefs: remove redundant initialization of pointer dst
bcachefs: remove redundant initializations of variables start_offset
and end_offset
bcachefs: remove duplicated assignment to variable offset_into_extent
bcachefs: remove redundant pointer q

Quoted 7 lines
 fs/bcachefs/btree_update_interior.c | 2 +-
 fs/bcachefs/buckets.c               | 2 +-
 fs/bcachefs/disk_groups.c           | 3 +--
 fs/bcachefs/fs-io.c                 | 4 ++--
 fs/bcachefs/io.c                    | 1 -
 fs/bcachefs/quota.c                 | 3 ---
 6 files changed, 5 insertions(+), 10 deletions(-)

Applied - thanks