public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] btrfs: extent_io: Handle memory allocation failure in __clear_extent_bit()
Date: Thu, 18 Apr 2019 15:21:14 +0800	[thread overview]
Message-ID: <20190418072114.4573-1-wqu@suse.com> (raw)

There is a BUG_ON() in __clear_extent_bit() for memory allocation
failure.

While comment of __clear_extent_bit() says it can return error, but we
always return 0.

Some __clear_extent_bit() callers just ignore the return value, while
some still expect error.

Let's return proper error for this memory allocation anyway, to remove
that BUG_ON() as a first step, so at least we can continue test.

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

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 828708f6510c..f1bfc632ef7b 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -743,7 +743,10 @@ int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
 
 	if (state->start < start) {
 		prealloc = alloc_extent_state_atomic(prealloc);
-		BUG_ON(!prealloc);
+		if (!prealloc) {
+			err = -ENOMEM;
+			goto out;
+		}
 		err = split_state(tree, state, prealloc, start);
 		if (err)
 			extent_io_tree_panic(tree, err);
@@ -766,7 +769,10 @@ int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
 	 */
 	if (state->start <= end && state->end > end) {
 		prealloc = alloc_extent_state_atomic(prealloc);
-		BUG_ON(!prealloc);
+		if (!prealloc) {
+			err = -ENOMEM;
+			goto out;
+		}
 		err = split_state(tree, state, prealloc, end + 1);
 		if (err)
 			extent_io_tree_panic(tree, err);
@@ -801,6 +807,8 @@ int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
 	if (prealloc)
 		free_extent_state(prealloc);
 
+	if (err)
+		return err;
 	return 0;
 
 }
-- 
2.21.0


             reply	other threads:[~2019-04-18  7:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-18  7:21 Qu Wenruo [this message]
2019-04-18  7:24 ` [PATCH] btrfs: extent_io: Handle memory allocation failure in __clear_extent_bit() Nikolay Borisov
2019-04-18  7:30   ` Qu Wenruo
2019-04-18 11:38     ` David Sterba
2019-04-18 11:51       ` Qu Wenruo
2019-04-18 11:54         ` Qu Wenruo
2019-04-18 12:27           ` Nikolay Borisov
2019-04-18 12:44             ` Qu Wenruo
2019-04-22  5:44           ` Qu Wenruo
2019-04-18 14:10   ` Josef Bacik
2019-04-18 14:15     ` 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=20190418072114.4573-1-wqu@suse.com \
    --to=wqu@suse.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