Re: [Patch v3 02/13] x86/speculation: Remove unnecessary ret variable in cpu_show_common

From: Thomas Gleixner
Date: Thu Oct 18 2018 - 08:47:10 EST


On Wed, 17 Oct 2018, Tim Chen wrote:

> Remove unecessary ret variable in cpu_show_common.
>
> Break up long lines too to make the code more concise
> and easier to read and modify in later patches.

So this does two things at once.

> static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,
> char *buf, unsigned int bug)
> {
> - int ret;
> -
> if (!boot_cpu_has_bug(bug))
> return sprintf(buf, "Not affected\n");
>
> @@ -873,13 +871,17 @@ static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr
> return sprintf(buf, "Mitigation: __user pointer sanitization\n");
>
> case X86_BUG_SPECTRE_V2:
> - ret = sprintf(buf, "%s%s%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],
> - boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "",
> - boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "",
> - (x86_spec_ctrl_base & SPEC_CTRL_STIBP) ? ", STIBP" : "",
> - boot_cpu_has(X86_FEATURE_RSB_CTXSW) ? ", RSB filling" : "",
> - spectre_v2_module_string());
> - return ret;
> + return sprintf(buf, "%s%s%s%s%s%s\n",
> + spectre_v2_strings[spectre_v2_enabled],
> + boot_cpu_has(X86_FEATURE_USE_IBPB) ?
> + ", IBPB" : "",
> + boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ?
> + ", IBRS_FW" : "",
> + (x86_spec_ctrl_base & SPEC_CTRL_STIBP) ?
> + ", STIBP" : "",
> + boot_cpu_has(X86_FEATURE_RSB_CTXSW) ?
> + ", RSB filling" : "",

And I do not agree at all that this is more readable.

IMO it's actually worse and I do not see how that makes it easier to
modify.

Thanks,

tglx