Commit 65336158 authored by robbieko's avatar robbieko Committed by David Sterba
Browse files

btrfs: replace ASSERT with proper error handling in stripe lookup fallback



After falling back to the previous item in btrfs_delete_raid_extent(),
the code uses ASSERT(found_start <= start) to verify the found extent
actually precedes our target range. If the B-tree state is unexpected
(e.g. no overlapping extent exists), this triggers a kernel BUG/panic
in debug builds, or silently continues with wrong data otherwise.

Replace the ASSERT with a proper bounds check that returns -ENOENT if
the found extent does not actually overlap with the start position.

Signed-off-by: default avatarrobbieko <robbieko@synology.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 1871ae78
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -154,7 +154,10 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le
			btrfs_item_key_to_cpu(leaf, &key, slot);
			found_start = key.objectid;
			found_end = found_start + key.offset;
			ASSERT(found_start <= start);
			if (found_start > start || found_end <= start) {
				ret = -ENOENT;
				break;
			}
		}

		if (key.type != BTRFS_RAID_STRIPE_KEY)