[Motorola Edge 40 Pro  / Moto X40 (China)] mxz55:
With this device, when you flash init_boot.img in Fastboot-bootloader mode, and that .img is patched by Magisk, the following error will result:

Sending 'init_boot_a' (8192 KB) OKAY [ 0.187s]
Writing 'init_boot_a' (bootloader) Preflash validation failed
FAILED (remote: '')
fastboot: error: Command failed

The error being (bootloader) Preflash validation failed, only on init_boot.img

The solution is simple. Just reboot into Fastboot-Fastboot mode (fastbootD) instead of Fastboot-bootloader. To do this, while still in bootloader mode, send the following command:

fastboot reboot fastboot (you were previously in the mode triggered by `fastboot reboot bootloader` or by booting up the phone while holding Volume Down button). While in Fastboot-Fastboot mode, you repeat flashing the images, and you'll successfully have root as they do succeed to flash this time.

Now that i've described the solution as simple as possible, i will move on to discussing what's actually happening here.

I don't know. This problem begun a couple months ago, it only affects my rtwo (Motorola Edge 40 Pro) and not for example my Motorola Edge 30. It would rather be a rtwo thing, instead of a Motorola thing. Perhaps Magisk patcher was updated in a way that it no longer works well with something that rtwo bootloader verifies during the flashing process. Maybe someone wants to file a Magisk issue report soon, or see if the problem lies on the side of Motorola's bootloader or Magisk. It also happens to the latest Magisk builds, including Canary channel and "Actions" builds, up to as recent as this week's.

My procedure when rooting the device (This can also be used as a mini guide for rooting rtwo: Motorola Edge 40 Pro, Edge+ (2023), Moto X40):

1. install LineageOS for rtwo

2. install latest Magisk app

3. move LineageOS boot.img and init_boot.img to the device storage

4. open Magisk app and let it patch boot.img and init_boot.img

5. open adb, connect USB cable, check with "adb devices", then send command "adb reboot bootloader". You are now in Fastboot-bootloader mode

6. Send commands: fastboot flash --slot=all boot boot.img and then: fastboot flash --slot=all init_boot init_boot.img

The results:

Tools\adb>fastboot flash --slot=all boot boot.img

Sending 'boot_a' (98304 KB) OKAY [ 2.248s]
Writing 'boot_a' OKAY [ 0.832s]
Sending 'boot_b' (98304 KB) OKAY [ 2.251s]
Writing 'boot_b' OKAY [ 0.852s]
Finished. Total time: 6.193s

Tools\adb>fastboot flash --slot=all init_boot init_boot.img
Sending 'init_boot_a' (8192 KB) OKAY [ 0.187s]
Writing 'init_boot_a' (bootloader) Preflash validation failed
FAILED (remote: '')
fastboot: error: Command failed

You can see the failure i described in last step. So, what i do now, is send command: fastboot reboot fastboot

You are now in Fastboot-Fastboot mode. We will just retry the same commands, but rather, in this mode..

The results (in Fastboot-Fastboot mode):

Tools\adb>fastboot flash --slot=all boot boot.img

Sending 'boot_a' (98304 KB) OKAY [ 2.293s]
Writing 'boot_a' OKAY [ 0.107s]
Sending 'boot_b' (98304 KB) OKAY [ 2.315s]
Writing 'boot_b' OKAY [ 0.108s]
Finished. Total time: 4.846s

Tools\adb>fastboot flash --slot=all init_boot init_boot.img
Sending 'init_boot_a' (8192 KB) OKAY [ 0.199s]
Writing 'init_boot_a' OKAY [ 0.039s]
Sending 'init_boot_b' (8192 KB) OKAY [ 0.191s]
Writing 'init_boot_b' OKAY [ 0.038s]
Finished. Total time: 0.476s

There we go. I prefer to do it in both modes, actually did since ever, to ensure it's really written. Before any such issue, i used to sometimes observe no root access in Magisk post-flashing in bootloader mode only, so i made it my good practise to let it to a pass through both bootloader and dedicated fastboot mode. It only takes a couple seconds more anyways. In this case, the practise made me work around this error message. I made this topic to avoid others from getting stuck, and maybe someone knows how to isolate and report the bug. Please leave feedback if you know more about it.