]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: clarify error returns values in __load_free_space_cache
authorZhihao Cheng <chengzhihao1@huawei.com>
Fri, 20 Nov 2020 01:08:04 +0000 (09:08 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 3 Mar 2021 15:44:17 +0000 (16:44 +0100)
[ Upstream commit 3cc64e7ebfb0d7faaba2438334c43466955a96e8 ]

Return value in __load_free_space_cache is not properly set after
(unlikely) memory allocation failures and 0 is returned instead.
This is not a problem for the caller load_free_space_cache because only
value 1 is considered as 'cache loaded' but for clarity it's better
to set the errors accordingly.

Fixes: a67509c30079 ("Btrfs: add a io_ctl struct and helpers for dealing with the space cache")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/free-space-cache.c

index 05b1b0f99f0bc39b658cf6d4237b1887a30b9308..55d8020afc5834c7939153c1a2d09dda98f6c671 100644 (file)
@@ -754,8 +754,10 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
        while (num_entries) {
                e = kmem_cache_zalloc(btrfs_free_space_cachep,
                                      GFP_NOFS);
-               if (!e)
+               if (!e) {
+                       ret = -ENOMEM;
                        goto free_cache;
+               }
 
                ret = io_ctl_read_entry(&io_ctl, e, &type);
                if (ret) {
@@ -764,6 +766,7 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
                }
 
                if (!e->bytes) {
+                       ret = -1;
                        kmem_cache_free(btrfs_free_space_cachep, e);
                        goto free_cache;
                }
@@ -783,6 +786,7 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
                        num_bitmaps--;
                        e->bitmap = kzalloc(PAGE_CACHE_SIZE, GFP_NOFS);
                        if (!e->bitmap) {
+                               ret = -ENOMEM;
                                kmem_cache_free(
                                        btrfs_free_space_cachep, e);
                                goto free_cache;