Messages in this thread | | | Date | Mon, 4 Sep 2023 22:08:28 -0700 | From | Josh Poimboeuf <> | Subject | Re: [PATCH 16/23] x86/bugs: Remove default case for fully switched enums |
| |
On Sat, Sep 02, 2023 at 11:02:16AM +0200, Borislav Petkov wrote: > On Fri, Aug 25, 2023 at 12:01:47AM -0700, Josh Poimboeuf wrote: > > 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> > > --- > > arch/x86/kernel/cpu/bugs.c | 17 +++++++---------- > > 1 file changed, 7 insertions(+), 10 deletions(-) > > You could just as well take care of the default: cases in > update_srbds_msr(), retbleed_select_mitigation(), unpriv_ebpf_notify(), > spectre_v2_parse_user_cmdline() and cpu_show_common() and get rid of > them all in this file and have the compiler warn for all of them.
I tried that, but adding all the unused cases adds a LOT of noise. For example the switch statement in spectre_v2_parse_user_cmdline() has eight unused enums. 'default' is much more compact and readable than a big list of all the unused enums which aren't really relevant there.
And in other places it added confusion. e.g., "RETBLEED_MITIGATION_NONE isn't possible here, why is it being checked?"
It's a balance between readability and robustness (which is itself affected by readability). So I just constrained the patch to switch statements which already handle all possible cases (as described above).
-- Josh
| |