btrfs: return error pointer from alloc_test_extent_buffer
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 3 Dec 2019 11:24:58 +0000 (14:24 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 4 Jan 2020 12:40:13 +0000 (13:40 +0100)
[ Upstream commit b6293c821ea8fa2a631a2112cd86cd435effeb8b ]

Callers of alloc_test_extent_buffer have not correctly interpreted the
return value as error pointer, as alloc_test_extent_buffer should behave
as alloc_extent_buffer. The self-tests were unaffected but
btrfs_find_create_tree_block could call both functions and that would
cause problems up in the call chain.

Fixes: faa2dbf004e8 ("Btrfs: add sanity tests for new qgroup accounting code")
CC: stable@vger.kernel.org # 4.4+
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.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/extent_io.c
fs/btrfs/tests/free-space-tree-tests.c
fs/btrfs/tests/qgroup-tests.c

index 4d901200be136962583ce5f5f30d10362e764f9d..37a28e2369b912aa18179d67ae83627ef30be6f6 100644 (file)
@@ -4994,12 +4994,14 @@ struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
                return eb;
        eb = alloc_dummy_extent_buffer(fs_info, start, nodesize);
        if (!eb)
-               return NULL;
+               return ERR_PTR(-ENOMEM);
        eb->fs_info = fs_info;
 again:
        ret = radix_tree_preload(GFP_NOFS);
-       if (ret)
+       if (ret) {
+               exists = ERR_PTR(ret);
                goto free_eb;
+       }
        spin_lock(&fs_info->buffer_lock);
        ret = radix_tree_insert(&fs_info->buffer_radix,
                                start >> PAGE_SHIFT, eb);
index a724d9a79bd20b63f6f4a589803637fc31a0f2be..5e3b875d87e2fee4ba9e081629ca915600ebe84c 100644 (file)
@@ -476,9 +476,9 @@ static int run_test(test_func_t test_func, int bitmaps, u32 sectorsize,
 
        root->node = alloc_test_extent_buffer(root->fs_info,
                nodesize, nodesize);
-       if (!root->node) {
-               test_msg("Couldn't allocate dummy buffer\n");
-               ret = -ENOMEM;
+       if (IS_ERR(root->node)) {
+               test_msg("couldn't allocate dummy buffer\n");
+               ret = PTR_ERR(root->node);
                goto out;
        }
        btrfs_set_header_level(root->node, 0);
index 9c6666692341aac6180bca2c2e0f1a20bb23dfd8..e0aa6b9786fa4f6c81ac89bebd6cacc469335ece 100644 (file)
@@ -488,9 +488,9 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
         */
        root->node = alloc_test_extent_buffer(root->fs_info, nodesize,
                                        nodesize);
-       if (!root->node) {
+       if (IS_ERR(root->node)) {
                test_msg("Couldn't allocate dummy buffer\n");
-               ret = -ENOMEM;
+               ret = PTR_ERR(root->node);
                goto out;
        }
        btrfs_set_header_level(root->node, 0);