Skip to content

Commit 0a0ce0d

Browse files
jpoimboebp3tk0v
authored andcommitted
x86/bugs: Remove default case for fully switched enums
For enum switch statements which handle all possible cases, remove the default case so a compiler warning gets printed if one of the enums gets accidentally omitted from the switch statement. Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Acked-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/fcf6feefab991b72e411c2aed688b18e65e06aed.1693889988.git.jpoimboe@kernel.org
1 parent 55ca901 commit 0a0ce0d

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

arch/x86/kernel/cpu/bugs.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,6 @@ static void __init retbleed_select_mitigation(void)
10191019

10201020
do_cmd_auto:
10211021
case RETBLEED_CMD_AUTO:
1022-
default:
10231022
if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD ||
10241023
boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) {
10251024
if (IS_ENABLED(CONFIG_CPU_UNRET_ENTRY))
@@ -1290,6 +1289,8 @@ spectre_v2_user_select_mitigation(void)
12901289

12911290
spectre_v2_user_ibpb = mode;
12921291
switch (cmd) {
1292+
case SPECTRE_V2_USER_CMD_NONE:
1293+
break;
12931294
case SPECTRE_V2_USER_CMD_FORCE:
12941295
case SPECTRE_V2_USER_CMD_PRCTL_IBPB:
12951296
case SPECTRE_V2_USER_CMD_SECCOMP_IBPB:
@@ -1301,8 +1302,6 @@ spectre_v2_user_select_mitigation(void)
13011302
case SPECTRE_V2_USER_CMD_SECCOMP:
13021303
static_branch_enable(&switch_mm_cond_ibpb);
13031304
break;
1304-
default:
1305-
break;
13061305
}
13071306

13081307
pr_info("mitigation: Enabling %s Indirect Branch Prediction Barrier\n",
@@ -2160,6 +2159,10 @@ static int l1d_flush_prctl_get(struct task_struct *task)
21602159
static int ssb_prctl_get(struct task_struct *task)
21612160
{
21622161
switch (ssb_mode) {
2162+
case SPEC_STORE_BYPASS_NONE:
2163+
if (boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS))
2164+
return PR_SPEC_ENABLE;
2165+
return PR_SPEC_NOT_AFFECTED;
21632166
case SPEC_STORE_BYPASS_DISABLE:
21642167
return PR_SPEC_DISABLE;
21652168
case SPEC_STORE_BYPASS_SECCOMP:
@@ -2171,11 +2174,8 @@ static int ssb_prctl_get(struct task_struct *task)
21712174
if (task_spec_ssb_disable(task))
21722175
return PR_SPEC_PRCTL | PR_SPEC_DISABLE;
21732176
return PR_SPEC_PRCTL | PR_SPEC_ENABLE;
2174-
default:
2175-
if (boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS))
2176-
return PR_SPEC_ENABLE;
2177-
return PR_SPEC_NOT_AFFECTED;
21782177
}
2178+
BUG();
21792179
}
21802180

21812181
static int ib_prctl_get(struct task_struct *task)
@@ -2504,9 +2504,6 @@ static void __init srso_select_mitigation(void)
25042504
pr_err("WARNING: kernel not compiled with CPU_SRSO.\n");
25052505
}
25062506
break;
2507-
2508-
default:
2509-
break;
25102507
}
25112508

25122509
out:

0 commit comments

Comments
 (0)