[v2] btrfs: returns -ENOMEM if path allocation failed in btrfs_cross_ref_exist()
diff mbox

Message ID 20180530064910.8724-1-suy.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Su Yue May 30, 2018, 6:49 a.m. UTC
btrfs_alloc_path() may fail due to no enough memory,
so let the function return -ENOMEM instead of -ENOENT is better.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
Changelog:
v2:
  Add commit message to describe the patch. Thanks Nikolay.
  
 fs/btrfs/extent-tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nikolay Borisov May 30, 2018, 6:44 a.m. UTC | #1
On 30.05.2018 09:49, Su Yue wrote:
> btrfs_alloc_path() may fail due to no enough memory,
> so let the function return -ENOMEM instead of -ENOENT is better.
> 
> Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
> ---
> Changelog:
> v2:
>   Add commit message to describe the patch. Thanks Nikolay.
>   
>  fs/btrfs/extent-tree.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 44093f92a532..99df6199dffc 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -3311,7 +3311,7 @@ int btrfs_cross_ref_exist(struct btrfs_root *root, u64 objectid, u64 offset,
>  
>  	path = btrfs_alloc_path();
>  	if (!path)
> -		return -ENOENT;
> +		return -ENOMEM;
>  
>  	do {
>  		ret = check_committed_ref(root, path, objectid,
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba May 30, 2018, 3:33 p.m. UTC | #2
On Wed, May 30, 2018 at 02:49:10PM +0800, Su Yue wrote:
> btrfs_alloc_path() may fail due to no enough memory,
> so let the function return -ENOMEM instead of -ENOENT is better.
> 
> Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>

Reviewed-by: David Sterba <dsterba@suse.com>

Thanks. I've audited all return codes after failed path allocation, this
was the only one not matching.

The return code of btrfs_cross_ref_exist should be also distinguished at
the call sites, as both places expect only the ENOENT but should not
react to ENOMEM as if it were ENOENT.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Su Yue May 31, 2018, 2:08 a.m. UTC | #3
On 05/30/2018 11:33 PM, David Sterba wrote:
> On Wed, May 30, 2018 at 02:49:10PM +0800, Su Yue wrote:
>> btrfs_alloc_path() may fail due to no enough memory,
>> so let the function return -ENOMEM instead of -ENOENT is better.
>>
>> Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
> 
> Reviewed-by: David Sterba <dsterba@suse.com>
> 
> Thanks. I've audited all return codes after failed path allocation, this
> was the only one not matching.
> 
> The return code of btrfs_cross_ref_exist should be also distinguished at
> the call sites, as both places expect only the ENOENT but should not
> react to ENOMEM as if it were ENOENT.
> 
Not quite understand the last paragraph. Is necessary to send patches to
make the two callers to distinguish ENOMEM and ENOENT?

Thanks,
Su

>

Patch
diff mbox

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 44093f92a532..99df6199dffc 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3311,7 +3311,7 @@  int btrfs_cross_ref_exist(struct btrfs_root *root, u64 objectid, u64 offset,
 
 	path = btrfs_alloc_path();
 	if (!path)
-		return -ENOENT;
+		return -ENOMEM;
 
 	do {
 		ret = check_committed_ref(root, path, objectid,