Skip to contentSkip to conversation

KVM: TDX: Fix uninitialized error code for __tdx_bringup()

PATCH Applied Tony Lindgren 2 participants 2 messages Sep 18, 2025 – Sep 24, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

Fixes 61bb28279623 ("KVM: TDX: Get system-wide info about TDX module on initialization")

---

This can wait for the merge window, not urgent

---
 arch/x86/kvm/vmx/tdx.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
arch/x86/kvm/vmx/tdx.c +3 -7
index ca9c8ec7dd01..66e53a90af94 100644
@@ -3460,12 +3460,11 @@ static int __init __tdx_bringup(void)
 	if (r)
 		goto tdx_bringup_err;
 
+	r = -EINVAL;
 	/* Get TDX global information for later use */
 	tdx_sysinfo = tdx_get_sysinfo();
-	if (WARN_ON_ONCE(!tdx_sysinfo)) {
-		r = -EINVAL;
+	if (WARN_ON_ONCE(!tdx_sysinfo))
 		goto get_sysinfo_err;
-	}
 
 	/* Check TDX module and KVM capabilities */
 	if (!tdx_get_supported_attrs(&tdx_sysinfo->td_conf) ||
@@ -3508,14 +3507,11 @@ static int __init __tdx_bringup(void)
 	if (td_conf->max_vcpus_per_td < num_present_cpus()) {
 		pr_err("Disable TDX: MAX_VCPU_PER_TD (%u) smaller than number of logical CPUs (%u).\n",
 				td_conf->max_vcpus_per_td, num_present_cpus());
-		r = -EINVAL;
 		goto get_sysinfo_err;
 	}
 
-	if (misc_cg_set_capacity(MISC_CG_RES_TDX, tdx_get_nr_guest_keyids())) {
-		r = -EINVAL;
+	if (misc_cg_set_capacity(MISC_CG_RES_TDX, tdx_get_nr_guest_keyids()))
 		goto get_sysinfo_err;
-	}
 
 	/*
 	 * Leave hardware virtualization enabled after TDX is enabled
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 9 lines · Tony Lindgren

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.

[...]

Applied to kvm-x86 vmx, thanks!

[1/1] KVM: TDX: Fix uninitialized error code for __tdx_bringup()

      https://github.com/kvm-x86/linux/commit/510c47f165f0

--
https://github.com/kvm-x86/linux/tree/next