get_tdx_sys_info() was generated by a script. It chains its metadata reads with: ret = ret ?: get_tdx_sys_info_foo(...); The function is maintained by hand now. Use conventional early returns instead. Print the module version only after its metadata has been read successfully. The "ret ?:" chain has no early exit, so the pr_info() after the version read prints a partially read or all-zero version when that read fails. That is harmless, but once every other read returns on error, a print after a failed read would look like a bug. AI was used under supervision to review code and workshop logs. Signed-off-by: Chao Gao Reviewed-by: Rick Edgecombe --- v4: - Collect tags [Rick] - Reword the justification for printing the version only after a successful read [Rick] v3: - Print the module version only after reading its metadata succeeds [Rick] --- arch/x86/virt/vmx/tdx/tdx.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index d9f2ace9993a..1700577ad5ad 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -529,19 +529,32 @@ static __init int get_tdx_sys_info_td_conf(struct tdx_sys_info_td_conf *td_conf) static __init int get_tdx_sys_info(struct tdx_sys_info *sysinfo) { - int ret = 0; + int ret; - ret = ret ?: read_sys_metadata_table(version_mappings, &sysinfo->version); + ret = read_sys_metadata_table(version_mappings, &sysinfo->version); + if (ret) + return ret; pr_info("Module version: " TDX_VERSION_FMT "\n", sysinfo->version.major_version, sysinfo->version.minor_version, sysinfo->version.update_version); - ret = ret ?: read_sys_metadata_table(features_mappings, &sysinfo->features); - ret = ret ?: read_sys_metadata_table(tdmr_mappings, &sysinfo->tdmr); - ret = ret ?: read_sys_metadata_table(td_ctrl_mappings, &sysinfo->td_ctrl); - ret = ret ?: get_tdx_sys_info_td_conf(&sysinfo->td_conf); + ret = read_sys_metadata_table(features_mappings, &sysinfo->features); + if (ret) + return ret; + + ret = read_sys_metadata_table(tdmr_mappings, &sysinfo->tdmr); + if (ret) + return ret; + + ret = read_sys_metadata_table(td_ctrl_mappings, &sysinfo->td_ctrl); + if (ret) + return ret; + + ret = get_tdx_sys_info_td_conf(&sysinfo->td_conf); + if (ret) + return ret; /* * The kernel supports using TDX without DPAMT, so @@ -549,10 +562,13 @@ static __init int get_tdx_sys_info(struct tdx_sys_info *sysinfo) * try to support buggy TDX modules that advertise * DPAMT but don't expose the metadata. */ - if (!ret && tdx_supports_dynamic_pamt(sysinfo)) + if (tdx_supports_dynamic_pamt(sysinfo)) { ret = read_sys_metadata_table(dpamt_mappings, &sysinfo->tdmr); + if (ret) + return ret; + } - return ret; + return 0; } static __init int check_features(struct tdx_sys_info *sysinfo) -- 2.52.0