diff options
| author | Feifei Xu <xufeifei@linux.vnet.ibm.com> | 2016-06-01 07:18:24 -0400 |
|---|---|---|
| committer | David Sterba <dsterba@suse.com> | 2016-06-02 13:22:49 -0400 |
| commit | 0ef6447a3d2f014e49069c4da33f905ed803aa2a (patch) | |
| tree | 4a6640e63442d44d32bedc2a6c854d998bc79872 | |
| parent | 5473e0c426ffaeaa19734987b153c2a7f33b8706 (diff) | |
Btrfs: Fix integer overflow when calculating bytes_per_bitmap
On ppc64, bytes_per_bitmap will be (65536*8*65536). Hence append UL to
fix integer overflow.
Reviewed-by: Josef Bacik <jbacik@fb.com>
Reviewed-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: Feifei Xu <xufeifei@linux.vnet.ibm.com>
Signed-off-by: David Sterba <dsterba@suse.com>
| -rw-r--r-- | fs/btrfs/free-space-cache.c | 12 | ||||
| -rw-r--r-- | fs/btrfs/tests/free-space-tests.c | 2 |
2 files changed, 7 insertions, 7 deletions
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index fa623359d5b8..2813ef0718a2 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
| @@ -29,7 +29,7 @@ | |||
| 29 | #include "inode-map.h" | 29 | #include "inode-map.h" |
| 30 | #include "volumes.h" | 30 | #include "volumes.h" |
| 31 | 31 | ||
| 32 | #define BITS_PER_BITMAP (PAGE_SIZE * 8) | 32 | #define BITS_PER_BITMAP (PAGE_SIZE * 8UL) |
| 33 | #define MAX_CACHE_BYTES_PER_GIG SZ_32K | 33 | #define MAX_CACHE_BYTES_PER_GIG SZ_32K |
| 34 | 34 | ||
| 35 | struct btrfs_trim_range { | 35 | struct btrfs_trim_range { |
| @@ -1415,11 +1415,11 @@ static inline u64 offset_to_bitmap(struct btrfs_free_space_ctl *ctl, | |||
| 1415 | u64 offset) | 1415 | u64 offset) |
| 1416 | { | 1416 | { |
| 1417 | u64 bitmap_start; | 1417 | u64 bitmap_start; |
| 1418 | u32 bytes_per_bitmap; | 1418 | u64 bytes_per_bitmap; |
| 1419 | 1419 | ||
| 1420 | bytes_per_bitmap = BITS_PER_BITMAP * ctl->unit; | 1420 | bytes_per_bitmap = BITS_PER_BITMAP * ctl->unit; |
| 1421 | bitmap_start = offset - ctl->start; | 1421 | bitmap_start = offset - ctl->start; |
| 1422 | bitmap_start = div_u64(bitmap_start, bytes_per_bitmap); | 1422 | bitmap_start = div64_u64(bitmap_start, bytes_per_bitmap); |
| 1423 | bitmap_start *= bytes_per_bitmap; | 1423 | bitmap_start *= bytes_per_bitmap; |
| 1424 | bitmap_start += ctl->start; | 1424 | bitmap_start += ctl->start; |
| 1425 | 1425 | ||
| @@ -1638,10 +1638,10 @@ static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl) | |||
| 1638 | u64 bitmap_bytes; | 1638 | u64 bitmap_bytes; |
| 1639 | u64 extent_bytes; | 1639 | u64 extent_bytes; |
| 1640 | u64 size = block_group->key.offset; | 1640 | u64 size = block_group->key.offset; |
| 1641 | u32 bytes_per_bg = BITS_PER_BITMAP * ctl->unit; | 1641 | u64 bytes_per_bg = BITS_PER_BITMAP * ctl->unit; |
| 1642 | u32 max_bitmaps = div_u64(size + bytes_per_bg - 1, bytes_per_bg); | 1642 | u64 max_bitmaps = div64_u64(size + bytes_per_bg - 1, bytes_per_bg); |
| 1643 | 1643 | ||
| 1644 | max_bitmaps = max_t(u32, max_bitmaps, 1); | 1644 | max_bitmaps = max_t(u64, max_bitmaps, 1); |
| 1645 | 1645 | ||
| 1646 | ASSERT(ctl->total_bitmaps <= max_bitmaps); | 1646 | ASSERT(ctl->total_bitmaps <= max_bitmaps); |
| 1647 | 1647 | ||
diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c index 0eeb8f3d6b67..f3756d6b9ba2 100644 --- a/fs/btrfs/tests/free-space-tests.c +++ b/fs/btrfs/tests/free-space-tests.c | |||
| @@ -22,7 +22,7 @@ | |||
| 22 | #include "../disk-io.h" | 22 | #include "../disk-io.h" |
| 23 | #include "../free-space-cache.h" | 23 | #include "../free-space-cache.h" |
| 24 | 24 | ||
| 25 | #define BITS_PER_BITMAP (PAGE_SIZE * 8) | 25 | #define BITS_PER_BITMAP (PAGE_SIZE * 8UL) |
| 26 | 26 | ||
| 27 | /* | 27 | /* |
| 28 | * This test just does basic sanity checking, making sure we can add an extent | 28 | * This test just does basic sanity checking, making sure we can add an extent |
