From b25c19f49ef294865462bf741e0430c59295ac15 Mon Sep 17 00:00:00 2001 From: Naohiro Aota Date: Tue, 25 Feb 2020 12:56:07 +0900 Subject: [PATCH] btrfs: handle invalid profile in chunk allocation Do not BUG_ON() when an invalid profile is passed to __btrfs_alloc_chunk(). Instead return -EINVAL with ASSERT() to catch a bug in the development stage. Suggested-by: Johannes Thumshirn Reviewed-by: Johannes Thumshirn Reviewed-by: Josef Bacik Signed-off-by: Naohiro Aota Reviewed-by: David Sterba Signed-off-by: David Sterba --- fs/btrfs/volumes.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 3d35466..f1c98b0 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4773,7 +4773,10 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, int j; int index; - BUG_ON(!alloc_profile_is_valid(type, 0)); + if (!alloc_profile_is_valid(type, 0)) { + ASSERT(0); + return -EINVAL; + } if (list_empty(&fs_devices->alloc_list)) { if (btrfs_test_opt(info, ENOSPC_DEBUG)) -- 2.7.4