From a99d13dccee11d29da3d045c2c2fc69d47eff770 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 19 Nov 2015 14:42:39 +0800 Subject: btrfs-progs: chunk-recovery: Fix a float point error Fix a zero division causing chunk-recovery fail. Also fix a typo "strpie_length" -> "stripe_length". Reported-by: Scotty Edmonds Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- btrfsck.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'btrfsck.h') diff --git a/btrfsck.h b/btrfsck.h index 0882a38..e16f52f 100644 --- a/btrfsck.h +++ b/btrfsck.h @@ -142,6 +142,23 @@ static inline unsigned long btrfs_chunk_record_size(int num_stripes) } void free_chunk_cache_tree(struct cache_tree *chunk_cache); +/* + * Function to check validation for num_stripes, or it can call + * float point error for 0 division + * return < 0 for invalid combination + * return 0 for valid combination + */ +static inline int check_num_stripes(u64 type, int num_stripes) +{ + if (num_stripes == 0) + return -1; + if (type & BTRFS_BLOCK_GROUP_RAID5 && num_stripes <= 1) + return -1; + if (type & BTRFS_BLOCK_GROUP_RAID6 && num_stripes <= 2) + return -1; + return 0; +} + u64 calc_stripe_length(u64 type, u64 length, int num_stripes); /* For block group tree */ static inline void block_group_tree_init(struct block_group_tree *tree) -- cgit v1.2.1