>+static int __tdx_td_init(struct kvm *kvm) >+{ >+ struct kvm_tdx *kvm_tdx = to_kvm_tdx(kvm); >+ cpumask_var_t packages; >+ unsigned long *tdcs_pa = NULL; >+ unsigned long tdr_pa = 0; >+ unsigned long va; >+ int ret, i; >+ u64 err; >+ >+ ret = tdx_guest_keyid_alloc(); >+ if (ret < 0) >+ return ret; >+ kvm_tdx->hkid = ret; >+ >+ va = __get_free_page(GFP_KERNEL_ACCOUNT); >+ if (!va) >+ goto free_hkid; @ret should be set to -ENOMEM before goto. otherwise, the error code would be the guest HKID. >+ tdr_pa = __pa(va); >+ >+ kvm_tdx->nr_tdcs_pages = tdx_sysinfo->td_ctrl.tdcs_base_size / PAGE_SIZE; >+ tdcs_pa = kcalloc(kvm_tdx->nr_tdcs_pages, sizeof(*kvm_tdx->tdcs_pa), >+ GFP_KERNEL_ACCOUNT | __GFP_ZERO); >+ if (!tdcs_pa) >+ goto free_tdr; ditto >+ >+ for (i = 0; i < kvm_tdx->nr_tdcs_pages; i++) { >+ va = __get_free_page(GFP_KERNEL_ACCOUNT); >+ if (!va) >+ goto free_tdcs; ditto >+ tdcs_pa[i] = __pa(va); >+ } >+ >+ if (!zalloc_cpumask_var(&packages, GFP_KERNEL)) { >+ ret = -ENOMEM; maybe just hoist this line before allocating tdr. >+ goto free_tdcs; >+ }