{
        *new_cr = ac->ac_criteria;
 
-       if (!should_optimize_scan(ac) || ac->ac_groups_linear_remaining)
+       if (!should_optimize_scan(ac) || ac->ac_groups_linear_remaining) {
+               *group = next_linear_group(ac, *group, ngroups);
                return;
+       }
 
        if (*new_cr == 0) {
                ext4_mb_choose_next_group_cr0(ac, new_cr, group, ngroups);
 ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
 {
        ext4_group_t prefetch_grp = 0, ngroups, group, i;
-       int cr = -1;
+       int cr = -1, new_cr;
        int err = 0, first_err = 0;
        unsigned int nr = 0, prefetch_ios = 0;
        struct ext4_sb_info *sbi;
                ac->ac_groups_linear_remaining = sbi->s_mb_max_linear_groups;
                prefetch_grp = group;
 
-               for (i = 0; i < ngroups; group = next_linear_group(ac, group, ngroups),
-                            i++) {
-                       int ret = 0, new_cr;
+               for (i = 0, new_cr = cr; i < ngroups; i++,
+                    ext4_mb_choose_next_group(ac, &new_cr, &group, ngroups)) {
+                       int ret = 0;
 
                        cond_resched();
-
-                       ext4_mb_choose_next_group(ac, &new_cr, &group, ngroups);
                        if (new_cr != cr) {
                                cr = new_cr;
                                goto repeat;