/*
         * reserve space for two commands every (1 << BLOCK_SIZE)
         *  entries or 2k dwords (whatever is smaller)
-         *
-         * The second command is for the shadow pagetables.
         */
+       ncmds = ((nptes >> min(adev->vm_manager.block_size, 11u)) + 1);
+
+       /* The second command is for the shadow pagetables. */
        if (vm->root.base.bo->shadow)
-               ncmds = ((nptes >> min(adev->vm_manager.block_size, 11u)) + 1) * 2;
-       else
-               ncmds = ((nptes >> min(adev->vm_manager.block_size, 11u)) + 1);
+               ncmds *= 2;
 
        /* padding, etc. */
        ndw = 64;
                ndw += ncmds * 10;
 
                /* extra commands for begin/end fragments */
+               ncmds = 2 * adev->vm_manager.fragment_size;
                if (vm->root.base.bo->shadow)
-                       ndw += 2 * 10 * adev->vm_manager.fragment_size * 2;
-               else
-                       ndw += 2 * 10 * adev->vm_manager.fragment_size;
+                       ncmds *= 2;
+
+               ndw += 10 * ncmds;
 
                params.func = amdgpu_vm_do_set_ptes;
        }