All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: don't BUG_ON() in btrfs_drop_extents()
@ 2024-11-28  9:34 Johannes Thumshirn
  2024-11-28 12:37 ` Filipe Manana
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Thumshirn @ 2024-11-28  9:34 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Johannes Thumshirn

From: Johannes Thumshirn <johannes.thumshirn@wdc.com>

btrfs_drop_extents() calls BUG_ON() in case the counter of to be deleted
extents is greater than 0 in two code paths. But both of these code paths
can handle errors, so there's no need to crash the kernel, but gracefully
bail out.

For developer builds with CONFIG_BTRFS_ASSERT turned on, ASSERT() that
this conditon is never met.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/btrfs/file.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index fbb753300071..33f0de10df5b 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -245,7 +245,11 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans,
 next_slot:
 		leaf = path->nodes[0];
 		if (path->slots[0] >= btrfs_header_nritems(leaf)) {
-			BUG_ON(del_nr > 0);
+			ASSERT(del_nr == 0);
+			if (del_nr > 0) {
+				ret = -EINVAL;
+				break;
+			}
 			ret = btrfs_next_leaf(root, path);
 			if (ret < 0)
 				break;
@@ -321,7 +325,11 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans,
 		 *  | -------- extent -------- |
 		 */
 		if (args->start > key.offset && args->end < extent_end) {
-			BUG_ON(del_nr > 0);
+			ASSERT(del_nr == 0);
+			if (del_nr > 0) {
+				ret = -EINVAL;
+				break;
+			}
 			if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
 				ret = -EOPNOTSUPP;
 				break;
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-28 15:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-28  9:34 [PATCH] btrfs: don't BUG_ON() in btrfs_drop_extents() Johannes Thumshirn
2024-11-28 12:37 ` Filipe Manana
2024-11-28 15:42   ` Johannes Thumshirn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.