Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

btrfs: return error pointer from alloc_test_extent_buffer

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>

authored by

Dan Carpenter and committed by
David Sterba
b6293c82 cf93e15e

+8 -6
+4 -2
fs/btrfs/extent_io.c
··· 5074 5074 return eb; 5075 5075 eb = alloc_dummy_extent_buffer(fs_info, start); 5076 5076 if (!eb) 5077 - return NULL; 5077 + return ERR_PTR(-ENOMEM); 5078 5078 eb->fs_info = fs_info; 5079 5079 again: 5080 5080 ret = radix_tree_preload(GFP_NOFS); 5081 - if (ret) 5081 + if (ret) { 5082 + exists = ERR_PTR(ret); 5082 5083 goto free_eb; 5084 + } 5083 5085 spin_lock(&fs_info->buffer_lock); 5084 5086 ret = radix_tree_insert(&fs_info->buffer_radix, 5085 5087 start >> PAGE_SHIFT, eb);
+2 -2
fs/btrfs/tests/free-space-tree-tests.c
··· 452 452 root->fs_info->tree_root = root; 453 453 454 454 root->node = alloc_test_extent_buffer(root->fs_info, nodesize); 455 - if (!root->node) { 455 + if (IS_ERR(root->node)) { 456 456 test_std_err(TEST_ALLOC_EXTENT_BUFFER); 457 - ret = -ENOMEM; 457 + ret = PTR_ERR(root->node); 458 458 goto out; 459 459 } 460 460 btrfs_set_header_level(root->node, 0);
+2 -2
fs/btrfs/tests/qgroup-tests.c
··· 484 484 * *cough*backref walking code*cough* 485 485 */ 486 486 root->node = alloc_test_extent_buffer(root->fs_info, nodesize); 487 - if (!root->node) { 487 + if (IS_ERR(root->node)) { 488 488 test_err("couldn't allocate dummy buffer"); 489 - ret = -ENOMEM; 489 + ret = PTR_ERR(root->node); 490 490 goto out; 491 491 } 492 492 btrfs_set_header_level(root->node, 0);