Skip to contentSkip to conversation

Btrfs: return ENOMEM rather than use BUG_ON when btrfs_alloc_path fails

PATCH In review Wang Shilong 2 participants 2 messages Feb 27, 2013 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 Btrfs: return ENOMEM rather than use BUG_ON when btrfs_alloc_path fails

From: Wang Shilong <[email protected]>

Return ENOMEM rather trigger BUG_ON, fix it.

---
 fs/btrfs/qgroup.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
fs/btrfs/qgroup.c +9 -3
index f011d9b..69fa487 100644
@@ -620,7 +620,9 @@ static int update_qgroup_limit_item(struct btrfs_trans_handle *trans,
 	key.offset = qgroupid;
 
 	path = btrfs_alloc_path();
-	BUG_ON(!path);
+	if (!path)
+		return -ENOMEM;
+
 	ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
 	if (ret > 0)
 		ret = -ENOENT;
@@ -661,7 +663,9 @@ static int update_qgroup_info_item(struct btrfs_trans_handle *trans,
 	key.offset = qgroup->qgroupid;
 
 	path = btrfs_alloc_path();
-	BUG_ON(!path);
+	if (!path)
+		return -ENOMEM;
+
 	ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
 	if (ret > 0)
 		ret = -ENOENT;
@@ -702,7 +706,9 @@ static int update_qgroup_status_item(struct btrfs_trans_handle *trans,
 	key.offset = 0;
 
 	path = btrfs_alloc_path();
-	BUG_ON(!path);
+	if (!path)
+		return -ENOMEM;
+
 	ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
 	if (ret > 0)
 		ret = -ENOENT;
Signature · 1 line
1.7.7.6
Reviewed-by on v1 2/3
#1 lore raw
Quoted 1 line

Return ENOMEM rather trigger BUG_ON, fix it.

These changes look good. The resulting surrounding state buildup and cleanup paths look correct.

Thanks for helping remove a few more BUG_ON()s :).