From: Qu Wenruo <wqu@suse.com>
To: Adarsh Das <adarshdas950@gmail.com>, clm@fb.com, dsterba@suse.com
Cc: terrelln@fb.com, linux-btrfs@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] btrfs: replace BUG() with error handling in compression.c
Date: Sat, 28 Feb 2026 06:52:01 +1030 [thread overview]
Message-ID: <07ebe143-13a4-47f6-8935-600a7cc50797@suse.com> (raw)
In-Reply-To: <20260227183111.9311-2-adarshdas950@gmail.com>
在 2026/2/28 05:01, Adarsh Das 写道:
> Replace BUG() calls with proper error handling. Where fs_info is
> available, use btrfs_err() and return -EUCLEAN. Where fs_info is
> not available,
btrfs_err() can accept a NULL pointer as @fs_info.
[...]
>
> @@ -874,11 +862,8 @@ static struct list_head *get_workspace(struct btrfs_fs_info *fs_info, int type,
> case BTRFS_COMPRESS_LZO: return btrfs_get_workspace(fs_info, type, level);
> case BTRFS_COMPRESS_ZSTD: return zstd_get_workspace(fs_info, level);
> default:
> - /*
> - * This can't happen, the type is validated several times
> - * before we get here.
> - */
> - BUG();
> + btrfs_err(fs_info, "invalid compression type %d", type);
> + return ERR_PTR(-EUCLEAN);
Although for such unknown compression level case, the workspace user and
put_workspace() are all erroring out correctly, it's not following the
common pattern of checking the error first.
I'd prefer to just remove those default: branch, and add an ASSERT()
checking the type is inside the BTRFS_NR_COMPRESS_TYPE before calling
switch().
Just as the comment said, the @type has been verify too many times, we
don't need to add a new error pattern where no one is checking.
Thanks,
Qu
> }
> }
>
> @@ -925,11 +910,8 @@ static void put_workspace(struct btrfs_fs_info *fs_info, int type, struct list_h
> case BTRFS_COMPRESS_LZO: return btrfs_put_workspace(fs_info, type, ws);
> case BTRFS_COMPRESS_ZSTD: return zstd_put_workspace(fs_info, ws);
> default:
> - /*
> - * This can't happen, the type is validated several times
> - * before we get here.
> - */
> - BUG();
> + btrfs_err(fs_info, "invalid compression type %d", type);
> + return;
> }
> }
>
next prev parent reply other threads:[~2026-02-27 20:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-27 18:31 [PATCH 0/4] btrfs: replace BUG() and BUG_ON() with error handling Adarsh Das
2026-02-27 18:31 ` [PATCH 1/4] btrfs: replace BUG() with error handling in compression.c Adarsh Das
2026-02-27 20:22 ` Qu Wenruo [this message]
2026-02-27 18:31 ` [PATCH 2/4] btrfs: clean coding style errors and warnings " Adarsh Das
2026-02-27 20:43 ` Qu Wenruo
2026-02-27 18:31 ` [PATCH 3/4] btrfs: replace BUG() and BUG_ON() with error handling in extent-tree.c Adarsh Das
2026-02-27 20:43 ` Qu Wenruo
2026-02-27 18:31 ` [PATCH 4/4] btrfs: clean coding style errors " Adarsh Das
2026-02-27 20:44 ` Qu Wenruo
2026-02-27 21:01 ` [PATCH 0/4] btrfs: replace BUG() and BUG_ON() with error handling 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=07ebe143-13a4-47f6-8935-600a7cc50797@suse.com \
--to=wqu@suse.com \
--cc=adarshdas950@gmail.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=terrelln@fb.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
all inboxes | Powered by JetHome®