Re: [PATCH 1/4] btrfs: replace BUG() with error handling in compression.c
From: Qu Wenruo
Date: Fri Feb 27 2026 - 15:22:20 EST
在 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;
}
}