btrfs: reflink: Initialize return value in btrfs_extent_same()
PATCH v2 1/1 btrfs: reflink: Initialize return value in btrfs_extent_same()
btrfs_extent_same() cannot be called with zero length. This patch add code that initialize ret as -EINVAL to make it safe.
---
v2:
- Removed assert and added initializing ret
--- fs/btrfs/reflink.c | 1 + 1 file changed, 1 insertion(+)
fs/btrfs/reflink.c +1 -0
@@ -653,6 +653,7 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,u64 i, tail_len, chunk_count;struct btrfs_root *root_dst =BTRFS_I (dst)->root; + ret = -EINVAL ;spin_lock (&root_dst->root_item_lock);if (root_dst->send_in_progress) { btrfs_warn_rl(root_dst->fs_info,
Signature · 1 line
2.25.1
Quoted 4 lines · Sidong Yang
btrfs_extent_same()cannot be called with zero length. This patch add code that initialize ret as-EINVALto make it safe.Signed-off-by Sidong Yang <[email protected]>
One minor nit: In this case the variable could have been initialized during definition to save 1 extra line of code.
Quoted 20 lines
---
v2:
- Removed assert and added initializing ret--- fs/btrfs/reflink.c | 1 + 1 file changed, 1 insertion(+)fs/btrfs/reflink.c +1
-0@@ -653,6 +653,7 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,u64 i, tail_len, chunk_count;struct btrfs_root *root_dst =BTRFS_I (dst)->root; + ret = -EINVAL ;spin_lock (&root_dst->root_item_lock);if (root_dst->send_in_progress) { btrfs_warn_rl(root_dst->fs_info,
Quoted 6 lines · Nikolay Borisov
Quoted 3 lines · Sidong Yang
btrfs_extent_same()cannot be called with zero length. This patch add code that initialize ret as-EINVALto make it safe.
Quoted 6 lines
Quoted 1 line
Signed-off-by Sidong Yang <[email protected]>Reviewed-by Nikolay Borisov <[email protected]>One minor nit: In this case the variable could have been initialized during definition to save 1 extra line of code.
Yeah the function is short enough to have the declaration initialization in sight, I've changed that.
Quoted 9 lines · David Sterba
Quoted 8 lines · Nikolay Borisov
Quoted 4 lines · Sidong Yang
btrfs_extent_same()cannot be called with zero length. This patch add code that initialize ret as-EINVALto make it safe.Signed-off-by Sidong Yang <[email protected]>
Quoted 7 lines
Quoted 4 lines
Reviewed-by Nikolay Borisov <[email protected]>One minor nit: In this case the variable could have been initialized during definition to save 1 extra line of code.
Yeah the function is short enough to have the declaration initialization in sight, I've changed that.
Thanks, I'll keep in mind. Any nit would be welcome.
Thanks,
Sidong
Quoted 3 lines · Sidong Yang
btrfs_extent_same()cannot be called with zero length. This patch add code that initialize ret as-EINVALto make it safe.
I suppose the motivation of the patch is to fix a warning from smatch, or other similar tools, about 'ret' not being initialized when olen is 0.
Initializing 'ret' to some value surely makes the warning go away, even though it's not possible for olen to be 0 at btrfs_extent_same(), as that
is filtered up in the call chain.
However setting to -EINVAL by default is confusing and counter intuitive because dedupe operations are supposed to return 0 (success) for a 0 length range.
So 'ret' should be initialized to 0 to avoid any confusion.
Thanks.
Quoted 24 lines
Signed-off-by Sidong Yang <[email protected]>---
v2:
- Removed assert and added initializing ret--- fs/btrfs/reflink.c | 1 + 1 file changed, 1 insertion(+)fs/btrfs/reflink.c +1
-1@@ -653,6 +653,7 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,u64 i, tail_len, chunk_count;struct btrfs_root *root_dst =BTRFS_I (dst)->root; + ret = -EINVAL ;spin_lock (&root_dst->root_item_lock);if (root_dst->send_in_progress) { btrfs_warn_rl(root_dst->fs_info, --2.25.1
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Quoted 8 lines · Filipe Manana
Quoted 3 lines · Sidong Yang
btrfs_extent_same()cannot be called with zero length. This patch add code that initialize ret as-EINVALto make it safe.I suppose the motivation of the patch is to fix a warning from smatch, or other similar tools, about 'ret' not being initialized when olen is 0.
Yes, Actually I used smatch you said.
Quoted 8 lines
Initializing 'ret' to some value surely makes the warning go away, even though it's not possible for olen to be 0 at
btrfs_extent_same(), as that
is filtered up in the call chain.However setting to
-EINVALby default is confusing and counter intuitive because dedupe operations are supposed to return 0 (success) for a 0 length range.
Yeah, I think it depends on btrfs_extent_same()'s concept. It does nothing when 0 length. It's okay if we consider it's normal operation and it seems natural.
Quoted 2 lines
So 'ret' should be initialized to 0 to avoid any confusion.
Agree. I want to know other people's thoughts.
Thanks,
Sidong
Quoted 32 lines
Thanks.
Quoted 24 lines
Signed-off-by Sidong Yang <[email protected]>---
v2:
- Removed assert and added initializing ret--- fs/btrfs/reflink.c | 1 + 1 file changed, 1 insertion(+)fs/btrfs/reflink.c +1
-1@@ -653,6 +653,7 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,u64 i, tail_len, chunk_count;struct btrfs_root *root_dst =BTRFS_I (dst)->root; + ret = -EINVAL ;spin_lock (&root_dst->root_item_lock);if (root_dst->send_in_progress) { btrfs_warn_rl(root_dst->fs_info, --2.25.1
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Quoted 11 lines · Sidong Yang
Quoted 8 lines · Filipe Manana
Quoted 3 lines · Sidong Yang
btrfs_extent_same()cannot be called with zero length. This patch add code that initialize ret as-EINVALto make it safe.I suppose the motivation of the patch is to fix a warning from smatch, or other similar tools, about 'ret' not being initialized when olen is 0.
Yes, Actually I used smatch you said.
It's good to mention that it's a warning reported by some tool, not all such warnings are valid or have to be fixed.
Quoted 9 lines
Quoted 8 lines
Initializing 'ret' to some value surely makes the warning go away, even though it's not possible for olen to be 0 at
btrfs_extent_same(), as that
is filtered up in the call chain.However setting to
-EINVALby default is confusing and counter intuitive because dedupe operations are supposed to return 0 (success) for a 0 length range.
Quoted 8 lines
Yeah, I think it depends on btrfs_extent_same()'s concept. It does nothing when 0 length. It's okay if we consider it's normal operation and it seems natural.
Quoted 2 lines
So 'ret' should be initialized to 0 to avoid any confusion.
Agree. I want to know other people's thoughts.
I agree with Filipe, please resend the patch with ret = 0 and explanation why want it. Thanks.