btrfs: scrub: clean up division in scrub_find_csum
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.

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

index 99f3a7e9eb61e6eb6e3288374f34f73eb6a6b6e5..a1b29d581dca05122f4a766d406a5172b8d25faf 100644 (file)
@@ -2708,7 +2708,9 @@ static int scrub_find_csum(struct scrub_ctx *sctx, u64 logical, u8 *csum)
        if (!sum)
                return 0;
 
-       index = ((u32)(logical - sum->bytenr)) / sctx->fs_info->sectorsize;
+       index = div_u64(logical - sum->bytenr, sctx->fs_info->sectorsize);
+       ASSERT(index < UINT_MAX);
+
        num_sectors = sum->len / sctx->fs_info->sectorsize;
        memcpy(csum, sum->sums + index, sctx->csum_size);
        if (index == num_sectors - 1) {