static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
                                           struct btrfs_block_group *bg,
-                                          struct map_lookup *map,
+                                          struct extent_map *em,
                                           struct btrfs_device *scrub_dev,
-                                          int stripe_index, u64 dev_extent_len)
+                                          int stripe_index)
 {
        struct btrfs_path *path;
        struct btrfs_fs_info *fs_info = sctx->fs_info;
        struct btrfs_root *root;
        struct btrfs_root *csum_root;
        struct blk_plug plug;
+       struct map_lookup *map = em->map_lookup;
        const u64 profile = map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK;
        const u64 chunk_logical = bg->start;
        int ret;
        u64 physical = map->stripes[stripe_index].physical;
-       const u64 physical_end = physical + dev_extent_len;
+       const u64 dev_stripe_len = btrfs_calc_stripe_length(em);
+       const u64 physical_end = physical + dev_stripe_len;
        u64 logical;
        u64 logic_end;
        /* The logical increment after finishing one stripe */
                physical += map->stripe_len;
                spin_lock(&sctx->stat_lock);
                if (stop_loop)
-                       sctx->stat.last_physical = map->stripes[stripe_index].physical +
-                                                  dev_extent_len;
+                       sctx->stat.last_physical =
+                               map->stripes[stripe_index].physical + dev_stripe_len;
                else
                        sctx->stat.last_physical = physical;
                spin_unlock(&sctx->stat_lock);
        for (i = 0; i < map->num_stripes; ++i) {
                if (map->stripes[i].dev->bdev == scrub_dev->bdev &&
                    map->stripes[i].physical == dev_offset) {
-                       ret = scrub_stripe(sctx, bg, map, scrub_dev, i,
-                                          dev_extent_len);
+                       ret = scrub_stripe(sctx, bg, em, scrub_dev, i);
                        if (ret)
                                goto out;
                }
 
                              devid, uuid);
 }
 
-static u64 calc_stripe_length(u64 type, u64 chunk_len, int num_stripes)
+u64 btrfs_calc_stripe_length(const struct extent_map *em)
 {
-       const int data_stripes = calc_data_stripes(type, num_stripes);
+       const struct map_lookup *map = em->map_lookup;
+       const int data_stripes = calc_data_stripes(map->type, map->num_stripes);
 
-       return div_u64(chunk_len, data_stripes);
+       return div_u64(em->len, data_stripes);
 }
 
 #if BITS_PER_LONG == 32
        map->type = type;
        map->sub_stripes = btrfs_chunk_sub_stripes(leaf, chunk);
        map->verified_stripes = 0;
-       em->orig_block_len = calc_stripe_length(type, em->len,
-                                               map->num_stripes);
+       em->orig_block_len = btrfs_calc_stripe_length(em);
        for (i = 0; i < num_stripes; i++) {
                map->stripes[i].physical =
                        btrfs_stripe_offset_nr(leaf, chunk, i);
        }
 
        map = em->map_lookup;
-       stripe_len = calc_stripe_length(map->type, em->len, map->num_stripes);
+       stripe_len = btrfs_calc_stripe_length(em);
        if (physical_len != stripe_len) {
                btrfs_err(fs_info,
 "dev extent physical offset %llu on devid %llu length doesn't match chunk %llu, have %llu expect %llu",
 
                           u64 logical, u64 len);
 unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
                                    u64 logical);
+u64 btrfs_calc_stripe_length(const struct extent_map *em);
 int btrfs_chunk_alloc_add_chunk_item(struct btrfs_trans_handle *trans,
                                     struct btrfs_block_group *bg);
 int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset);