btrfs: scrub: clean up division in __scrub_mark_bitmap
authorDavid Sterba <dsterba@suse.com>
Fri, 31 Mar 2017 16:02:48 +0000 (18:02 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Aug 2017 15:47:42 +0000 (17:47 +0200)
Use proper helpers for 64bit division and then cast to narrower type.

Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/scrub.c

index 810fce2404898c32e102cc5c5b29b6d81c71f942..99f3a7e9eb61e6eb6e3288374f34f73eb6a6b6e5 100644 (file)
@@ -2620,7 +2620,8 @@ static inline void __scrub_mark_bitmap(struct scrub_parity *sparity,
                                       u64 start, u64 len)
 {
        u64 offset;
-       int nsectors;
+       u64 nsectors64;
+       u32 nsectors;
        int sectorsize = sparity->sctx->fs_info->sectorsize;
 
        if (len >= sparity->stripe_len) {
@@ -2631,7 +2632,10 @@ static inline void __scrub_mark_bitmap(struct scrub_parity *sparity,
        start -= sparity->logic_start;
        start = div64_u64_rem(start, sparity->stripe_len, &offset);
        offset = div_u64(offset, sectorsize);
-       nsectors = (int)len / sectorsize;
+       nsectors64 = div_u64(len, sectorsize);
+
+       ASSERT(nsectors64 < UINT_MAX);
+       nsectors = (u32)nsectors64;
 
        if (offset + nsectors <= sparity->nsectors) {
                bitmap_set(bitmap, offset, nsectors);