Re: [RFC PATCH v2 09/10] x86/virt/tdx: Use early returns in get_tdx_sys_info()
From: Chao Gao
Date: Thu Sep 24 2026 - 03:29:27 EST
>> static __init int get_tdx_sys_info(struct tdx_sys_info *sysinfo)
>> {
>> - int ret = 0;
>> + int ret;
>>
>> - ret = ret ?: get_tdx_sys_info_version(&sysinfo->version);
>> + ret = get_tdx_sys_info_version(&sysinfo->version);
>>
>> pr_info("Module version: " TDX_VERSION_FMT "\n",
>> sysinfo->version.major_version,
>> sysinfo->version.minor_version,
>> sysinfo->version.update_version);
>>
>> - ret = ret ?: get_tdx_sys_info_features(&sysinfo->features);
>> - ret = ret ?: get_tdx_sys_info_tdmr(&sysinfo->tdmr);
>> - ret = ret ?: get_tdx_sys_info_td_ctrl(&sysinfo->td_ctrl);
>> - ret = ret ?: get_tdx_sys_info_td_conf(&sysinfo->td_conf);
>> + if (ret)
>> + return ret;
>
>It should not print the module versions if it failed to read them, right? I
>think the reason why it was done this way was to fit into the existing pattern
>and because printing zeros is not a horrible outcome. But that code pattern
>caused problem no longer exists. So I'd think it's ok to fix it in this patch.
>Before it kind of blended in. But now it easily stands out as buggy.
Right. I'll move the error check before the pr_info() and mention it in
the changelog.