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 2/5] btrfs: extent_io: Unify the return value of __alloc_extent_buffer() with alloc_extent_buffer()
Date: Fri, 22 Feb 2019 18:16:41 +0800	[thread overview]
Message-ID: <20190222101645.4403-3-wqu@suse.com> (raw)
In-Reply-To: <20190222101645.4403-1-wqu@suse.com>

Although __alloc_extent_buffer() shouldn't fail due to its __GFP_NOFAIL
flag, to unify the return value type, let's pretend it will return
PTR_ERR() and never return NULL.

The direct callers are:
1) alloc_extent_buffer()
   It's the stub of the call chain, as the only caller is
   btrfs_find_create_tree_block(), and all its callers have already
   checked the return value correctly.

2) __alloc_dummy_extent_buffer()/alloc_dummy_extent_buffer
3) btrfs_clone_extent_buffer()

For call sites 2) and 3), this patch only checks the return value from
__alloc_extent_buffer() but still allow its caller to return NULL.
The NULL return value will be addressed in later commits.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/extent_io.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index b28a75546700..c73da1752041 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4661,6 +4661,11 @@ static inline void btrfs_release_extent_buffer(struct extent_buffer *eb)
 	__free_extent_buffer(eb);
 }
 
+/*
+ * This function should not fail due to its __GFP_NOFAIL flag.
+ *
+ * But caller should check for PTR_ERR() to be future-proof.
+ */
 static struct extent_buffer *
 __alloc_extent_buffer(struct btrfs_fs_info *fs_info, u64 start,
 		      unsigned long len)
@@ -4707,7 +4712,7 @@ struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src)
 	int num_pages = num_extent_pages(src);
 
 	new = __alloc_extent_buffer(src->fs_info, src->start, src->len);
-	if (new == NULL)
+	if (IS_ERR(new))
 		return NULL;
 
 	for (i = 0; i < num_pages; i++) {
@@ -4737,7 +4742,7 @@ struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
 	int i;
 
 	eb = __alloc_extent_buffer(fs_info, start, len);
-	if (!eb)
+	if (IS_ERR(eb))
 		return NULL;
 
 	num_pages = num_extent_pages(eb);
@@ -4921,7 +4926,7 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
 		return eb;
 
 	eb = __alloc_extent_buffer(fs_info, start, len);
-	if (!eb)
+	if (IS_ERR(eb))
 		return ERR_PTR(-ENOMEM);
 
 	num_pages = num_extent_pages(eb);
-- 
2.20.1


  parent reply	other threads:[~2019-02-22 10:16 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 ` Qu Wenruo [this message]
2019-02-22 10:16 ` [PATCH 3/5] btrfs: extent_io: Unify the return value of alloc_dummy_extent_buffer() with alloc_extent_buffer() Qu Wenruo
2019-02-22 10:16 ` [PATCH 4/5] btrfs: extent_io: Unify the return value of alloc_test_extent_buffer() " Qu Wenruo
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-3-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).