Skip to content

Commit 510c47f

Browse files
tony-lindgrensean-jc
authored andcommitted
KVM: TDX: Fix uninitialized error code for __tdx_bringup()
Fix a Smatch static checker warning reported by Dan: arch/x86/kvm/vmx/tdx.c:3464 __tdx_bringup() warn: missing error code 'r' Initialize r to -EINVAL before tdx_get_sysinfo() to simplify the code and to prevent similar issues from sneaking in later on as suggested by Kai. Cc: stable@vger.kernel.org Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Fixes: 61bb282 ("KVM: TDX: Get system-wide info about TDX module on initialization") Suggested-by: Kai Huang <kai.huang@intel.com> Reviewed-by: Kai Huang <kai.huang@intel.com> Signed-off-by: Tony Lindgren <tony.lindgren@linux.intel.com> Link: https://lore.kernel.org/r/20250918053226.802204-1-tony.lindgren@linux.intel.com [sean: tag for stable] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 7cbb14d commit 510c47f

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

arch/x86/kvm/vmx/tdx.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3457,12 +3457,11 @@ static int __init __tdx_bringup(void)
34573457
if (r)
34583458
goto tdx_bringup_err;
34593459

3460+
r = -EINVAL;
34603461
/* Get TDX global information for later use */
34613462
tdx_sysinfo = tdx_get_sysinfo();
3462-
if (WARN_ON_ONCE(!tdx_sysinfo)) {
3463-
r = -EINVAL;
3463+
if (WARN_ON_ONCE(!tdx_sysinfo))
34643464
goto get_sysinfo_err;
3465-
}
34663465

34673466
/* Check TDX module and KVM capabilities */
34683467
if (!tdx_get_supported_attrs(&tdx_sysinfo->td_conf) ||
@@ -3505,14 +3504,11 @@ static int __init __tdx_bringup(void)
35053504
if (td_conf->max_vcpus_per_td < num_present_cpus()) {
35063505
pr_err("Disable TDX: MAX_VCPU_PER_TD (%u) smaller than number of logical CPUs (%u).\n",
35073506
td_conf->max_vcpus_per_td, num_present_cpus());
3508-
r = -EINVAL;
35093507
goto get_sysinfo_err;
35103508
}
35113509

3512-
if (misc_cg_set_capacity(MISC_CG_RES_TDX, tdx_get_nr_guest_keyids())) {
3513-
r = -EINVAL;
3510+
if (misc_cg_set_capacity(MISC_CG_RES_TDX, tdx_get_nr_guest_keyids()))
35143511
goto get_sysinfo_err;
3515-
}
35163512

35173513
/*
35183514
* Leave hardware virtualization enabled after TDX is enabled

0 commit comments

Comments
 (0)