Skip to contentSkip to conversation

Btrfs: silence a compiler warning

PATCH Superseded Dan Carpenter 2 participants 4 messages Feb 22, 2012

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

PATCH 1/1 Btrfs: silence a compiler warning

Gcc warns that "ret" can be used uninitialized. It can't actually be used uninitialized because btrfs_num_copies() always returns 1 or more.

fs/btrfs/check-integrity.c +1 -1
index 064b29b..c053e90 100644
@@ -643,7 +643,7 @@ static struct btrfsic_dev_state *btrfsic_dev_state_hashtable_lookup(
 static int btrfsic_process_superblock(struct btrfsic_state *state,
 				      struct btrfs_fs_devices *fs_devices)
 {
-	int ret;
+	int ret = 0;
 	struct btrfs_super_block *selected_super;
 	struct list_head *dev_head = &fs_devices->devices;
 	struct btrfs_device *device;
#1 lore raw
Quoted 10 lines · Dan Carpenter

Gcc warns that "ret" can be used uninitialized. It can't actually be used uninitialized because btrfs_num_copies() always returns 1 or more.

fs/btrfs/check-integrity.c +0 -0
index 064b29b..c053e90 100644

fs/btrfs/check-integrity.c static struct btrfsic_dev_state *btrfsic_dev_state_hashtable_lookup( · line 646

Quoted 5 lines
fs/btrfs/check-integrity.c +1 -1
@@ -643,7 +643,7 @@ static struct btrfsic_dev_state *btrfsic_dev_state_hashtable_lookup(
 static int btrfsic_process_superblock(struct btrfsic_state *state,
 				      struct btrfs_fs_devices *fs_devices)
 {
-	int ret;
+	int ret = 0;

Does

	int uninitialized_var(ret);

work? The assignment to zero actually generates additional (unnecessary) code.

David

#2 lore raw
Quoted 19 lines · David Brown
Quoted 10 lines · Dan Carpenter

Gcc warns that "ret" can be used uninitialized. It can't actually be used uninitialized because btrfs_num_copies() always returns 1 or more.

fs/btrfs/check-integrity.c +0 -0
index 064b29b..c053e90 100644

fs/btrfs/check-integrity.c static struct btrfsic_dev_state *btrfsic_dev_state_hashtable_lookup( · line 646

Quoted 5 lines
fs/btrfs/check-integrity.c +1 -1
@@ -643,7 +643,7 @@ static struct btrfsic_dev_state *btrfsic_dev_state_hashtable_lookup(
 static int btrfsic_process_superblock(struct btrfsic_state *state,
 				      struct btrfs_fs_devices *fs_devices)
 {
-	int ret;
+	int ret = 0;

Does

Quoted 4 lines
	int uninitialized_var(ret);

work? The assignment to zero actually generates additional (unnecessary) code.

Sure. I can resend it.

regards,
dan carpenter

#3 lore raw

PATCH v2 1/1 Btrfs: silence a compiler warning

In reply to David Brown

Gcc warns that "ret" can be used uninitialized. It can't actually be used uninitialized because btrfs_num_copies() always returns 1 or more.

---
v2: use the uninitialized_var() macro instead of initializing to 0.

fs/btrfs/check-integrity.c +1 -1
index 064b29b..3bb3853 100644
@@ -643,7 +643,7 @@ static struct btrfsic_dev_state *btrfsic_dev_state_hashtable_lookup(
 static int btrfsic_process_superblock(struct btrfsic_state *state,
 				      struct btrfs_fs_devices *fs_devices)
 {
-	int ret;
+	int uninitialized_var(ret);
 	struct btrfs_super_block *selected_super;
 	struct list_head *dev_head = &fs_devices->devices;
 	struct btrfs_device *device;