From: Nikolay Borisov <nborisov@suse.com>
To: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Cc: Josef Bacik <josef@toxicpanda.com>
Subject: Re: [PATCH] btrfs: extent_io: Handle memory allocation failure in __clear_extent_bit()
Date: Thu, 18 Apr 2019 10:24:10 +0300 [thread overview]
Message-ID: <b2ff0fa1-9fec-46e1-75f5-e7903523063f@suse.com> (raw)
In-Reply-To: <20190418072114.4573-1-wqu@suse.com>
On 18.04.19 г. 10:21 ч., Qu Wenruo wrote:
> 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.
I remember Josef did some changes into this code and said that prealloc
shouldn't fail because this will cause mayhem down the road i.e. proper
error handling is missing. If anything I think it should be added first
and then remove the BUG_ONs.
>
> 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;
>
> }
>
next prev parent reply other threads:[~2019-04-18 7:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-18 7:21 [PATCH] btrfs: extent_io: Handle memory allocation failure in __clear_extent_bit() Qu Wenruo
2019-04-18 7:24 ` Nikolay Borisov [this message]
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=b2ff0fa1-9fec-46e1-75f5-e7903523063f@suse.com \
--to=nborisov@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.com \
/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