[PATCH 0/4] btrfs: replace BUG() and BUG_ON() with error handling

Adarsh Das posted 4 patches 1 month, 2 weeks ago
fs/btrfs/compression.c | 66 ++++++++++++-------------------
fs/btrfs/extent-tree.c | 89 +++++++++++++++++++++++++++++++-----------
2 files changed, 91 insertions(+), 64 deletions(-)
[PATCH 0/4] btrfs: replace BUG() and BUG_ON() with error handling
Posted by Adarsh Das 1 month, 2 weeks ago
Replace BUG() and BUG_ON() calls in compression.c and extent-tree.c
with proper error handling so the kernel does not crash on unexpected
conditions. Also fix checkpatch warnings and errors found in both files.

Adarsh Das (4):
  btrfs: replace BUG() with error handling in compression.c
  btrfs: clean coding style errors and warnings in compression.c
  btrfs: replace BUG() and BUG_ON() with error handling in extent-tree.c
  btrfs: clean coding style errors in extent-tree.c

 fs/btrfs/compression.c | 66 ++++++++++++-------------------
 fs/btrfs/extent-tree.c | 89 +++++++++++++++++++++++++++++++-----------
 2 files changed, 91 insertions(+), 64 deletions(-)

-- 
2.53.0
Re: [PATCH 0/4] btrfs: replace BUG() and BUG_ON() with error handling
Posted by Qu Wenruo 1 month, 2 weeks ago

在 2026/2/28 05:01, Adarsh Das 写道:
> Replace BUG() and BUG_ON() calls in compression.c and extent-tree.c
> with proper error handling so the kernel does not crash on unexpected
> conditions.

I think one needs to distinguish sanity checks and real proper error 
handling.

I'd say, if some parameter/values are only generated from runtime code, 
you're doing sanity checks, and it applies to most of your fixes.

In that case, ASSERT() is preferred, and should be checked as early as 
possible (e.g. checks before adding something to a list/rbtree, other 
than checking when handling the list/rbtree entry).

And if some developer hits that ASSERT() frequently enough, we can later 
change it to a proper error handling later.



If something is read from the disk, it needs proper error handling, but 
in that case it should be done in tree-checker, which provides a more 
concentrated place to do such checks.

In the original location where there is a BUG_ON(), after making sure 
it's already covered by tree-checker (or adding the missing check), 
replacing the BUG_ON() with an ASSERT().


> Also fix checkpatch warnings and errors found in both files.

For such code style errors, fix them inside the real helpful patches 
instead.

Thanks,
Qu

> 
> Adarsh Das (4):
>    btrfs: replace BUG() with error handling in compression.c
>    btrfs: clean coding style errors and warnings in compression.c
>    btrfs: replace BUG() and BUG_ON() with error handling in extent-tree.c
>    btrfs: clean coding style errors in extent-tree.c
> 
>   fs/btrfs/compression.c | 66 ++++++++++++-------------------
>   fs/btrfs/extent-tree.c | 89 +++++++++++++++++++++++++++++++-----------
>   2 files changed, 91 insertions(+), 64 deletions(-)
>