Skip to contentSkip to conversation

btrfs: reflink: Initialize return value to 0 in btrfs_extent_same()

PATCH In review Sidong Yang 3 participants 3 messages Aug 26, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 btrfs: reflink: Initialize return value to 0 in btrfs_extent_same()

This patch fixes a warning reported by smatch. It reported that ret could be returned without initialized. 0 would be proper value for initializing ret. Because dedupe operations are supposed to to return 0 for a 0 length range.

---
v2:
- Removed assert and added initializing ret
v3:
- Changed initializing value to 0

---
 fs/btrfs/reflink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/reflink.c +1 -1
index 9b0814318e72..c71e49782e86 100644
@@ -649,7 +649,7 @@ static int btrfs_extent_same_range(struct inode *src, u64 loff, u64 len,
 static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,
 			     struct inode *dst, u64 dst_loff)
 {
-	int ret;
+	int ret = 0;
 	u64 i, tail_len, chunk_count;
 	struct btrfs_root *root_dst = BTRFS_I(dst)->root;
 
Signature · 1 line
2.25.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 7 lines · Sidong Yang

This patch fixes a warning reported by smatch. It reported that ret could be returned without initialized. 0 would be proper value for initializing ret. Because dedupe operations are supposed to to return 0 for a 0 length range.

Looks good, thanks.

Quoted 25 lines

---
v2:
- Removed assert and added initializing ret
v3:
- Changed initializing value to 0

---
 fs/btrfs/reflink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/reflink.c +1 -2
index 9b0814318e72..c71e49782e86 100644
@@ -649,7 +649,7 @@ static int btrfs_extent_same_range(struct inode *src, u64 loff, u64 len,
 static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,
                             struct inode *dst, u64 dst_loff)
 {
-       int ret;
+       int ret = 0;
        u64 i, tail_len, chunk_count;
        struct btrfs_root *root_dst = BTRFS_I(dst)->root;
 
--

2.25.1

Signature · 3 lines
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”
#2 lore raw
In reply to Sidong Yang
Quoted 11 lines · Sidong Yang

This patch fixes a warning reported by smatch. It reported that ret could be returned without initialized. 0 would be proper value for initializing ret. Because dedupe operations are supposed to to return 0 for a 0 length range.

---
v2:
- Removed assert and added initializing ret
v3:
- Changed initializing value to 0

I've slightly rephrased the changelog, added to misc-next, thanks.