kexec: move segment verification code in a separate function