linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: dan.carpenter@oracle.com
Subject: [PATCH 4/5] btrfs: extent_io: Unify the return value of alloc_test_extent_buffer() with alloc_extent_buffer()
Date: Fri, 22 Feb 2019 18:16:43 +0800	[thread overview]
Message-ID: <20190222101645.4403-5-wqu@suse.com> (raw)
In-Reply-To: <20190222101645.4403-1-wqu@suse.com>

The function only get called in two locations:
1) free-space-tree-tests.c
2) qgroup-tests.c
   These call sites are stubs.

3) btrfs_find_create_tree_block()
   Since all existing btrfs_find_create_tree_block() callers handles
   the return value correctly, it's also a stub.

So all alloc_test_extent_buffer() callers should be covered by this
patch.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/extent_io.c                   | 21 +++++++++++----------
 fs/btrfs/tests/free-space-tree-tests.c |  3 ++-
 fs/btrfs/tests/qgroup-tests.c          |  3 ++-
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index f9c9da9b84a3..a19bd8bc3b32 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4863,6 +4863,7 @@ struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info,
 }
 
 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
+/* Will either return valid pointer or PTR_ERR(), NEVER NULL pointer. */
 struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
 					u64 start)
 {
@@ -4874,12 +4875,14 @@ struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
 		return eb;
 	eb = alloc_dummy_extent_buffer(fs_info, start);
 	if (IS_ERR(eb))
-		return NULL;
+		return eb;
 	eb->fs_info = fs_info;
 again:
 	ret = radix_tree_preload(GFP_NOFS);
-	if (ret)
-		goto free_eb;
+	if (ret) {
+		btrfs_release_extent_buffer(eb);
+		return ERR_PTR(ret);
+	}
 	spin_lock(&fs_info->buffer_lock);
 	ret = radix_tree_insert(&fs_info->buffer_radix,
 				start >> PAGE_SHIFT, eb);
@@ -4887,18 +4890,16 @@ struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
 	radix_tree_preload_end();
 	if (ret == -EEXIST) {
 		exists = find_extent_buffer(fs_info, start);
-		if (exists)
-			goto free_eb;
-		else
-			goto again;
+		if (exists) {
+			btrfs_release_extent_buffer(eb);
+			return exists;
+		}
+		goto again;
 	}
 	check_buffer_tree_ref(eb);
 	set_bit(EXTENT_BUFFER_IN_TREE, &eb->bflags);
 
 	return eb;
-free_eb:
-	btrfs_release_extent_buffer(eb);
-	return exists;
 }
 #endif
 
diff --git a/fs/btrfs/tests/free-space-tree-tests.c b/fs/btrfs/tests/free-space-tree-tests.c
index 89346da890cf..025fce63959a 100644
--- a/fs/btrfs/tests/free-space-tree-tests.c
+++ b/fs/btrfs/tests/free-space-tree-tests.c
@@ -462,7 +462,8 @@ static int run_test(test_func_t test_func, int bitmaps, u32 sectorsize,
 	root->fs_info->tree_root = root;
 
 	root->node = alloc_test_extent_buffer(root->fs_info, nodesize);
-	if (!root->node) {
+	if (IS_ERR(root->node)) {
+		root->node = NULL;
 		test_err("couldn't allocate dummy buffer");
 		ret = -ENOMEM;
 		goto out;
diff --git a/fs/btrfs/tests/qgroup-tests.c b/fs/btrfs/tests/qgroup-tests.c
index 412b910b04cc..536600eb4d9d 100644
--- a/fs/btrfs/tests/qgroup-tests.c
+++ b/fs/btrfs/tests/qgroup-tests.c
@@ -484,7 +484,8 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
 	 * *cough*backref walking code*cough*
 	 */
 	root->node = alloc_test_extent_buffer(root->fs_info, nodesize);
-	if (!root->node) {
+	if (IS_ERR(root->node)) {
+		root->node = NULL;
 		test_err("couldn't allocate dummy buffer");
 		ret = -ENOMEM;
 		goto out;
-- 
2.20.1


  parent reply	other threads:[~2019-02-22 10:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-22 10:16 [PATCH 0/5] Unify the return value of alloc/clone_extent_buffer() Qu Wenruo
2019-02-22 10:16 ` [PATCH 1/5] btrfs: extent_io: Add comment about the return value of alloc_extent_buffer() Qu Wenruo
2019-02-27 13:36   ` David Sterba
2019-02-27 13:41     ` Qu Wenruo
2019-02-27 13:44       ` David Sterba
2019-02-22 10:16 ` [PATCH 2/5] btrfs: extent_io: Unify the return value of __alloc_extent_buffer() with alloc_extent_buffer() Qu Wenruo
2019-02-22 10:16 ` [PATCH 3/5] btrfs: extent_io: Unify the return value of alloc_dummy_extent_buffer() " Qu Wenruo
2019-02-22 10:16 ` Qu Wenruo [this message]
2019-02-22 10:16 ` [PATCH 5/5] btrfs: extent_io: Unify the return value of btrfs_clone_extent_buffer() " Qu Wenruo
2019-02-22 12:47   ` Nikolay Borisov
2019-02-22 12:53     ` Qu Wenruo
2019-02-22 13:02   ` [PATCH v1.1 " Qu Wenruo
2019-02-22 12:54 ` [PATCH 0/5] Unify the return value of alloc/clone_extent_buffer() Nikolay Borisov
2019-02-22 13:02   ` Qu Wenruo
2019-02-22 13:29     ` Nikolay Borisov
2019-02-22 13:31       ` Qu Wenruo
2019-02-27 14:11         ` David Sterba
2019-02-22 13:32       ` Qu Wenruo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190222101645.4403-5-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=dan.carpenter@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).