From 9d4053df76c127f625a8571d3ef16e6a063c8de5 Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Wed, 18 Nov 2020 16:31:27 -0800 Subject: [PATCH] Revert "Reland: Clean up implicit fall through." This reverts commit 6208b9aa9c4e8b7c9ff8063965c9f9aa519c1740. Upstream coreboot has raised concerns that relying on GCC 7+ features for host utilities is too restrictive, so revert this and go back to customizing fallthrough annotations by compiler. Cleaned out some of the C++-specific stuff because vboot isn't built with C++. BRANCH=None BUG=None TEST=Built with clang and GCC. Change-Id: I75d796d289b0a6c249fc8ac2dadb1453be468642 Signed-off-by: Julius Werner Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2547821 Reviewed-by: Manoj Gupta Reviewed-by: Joel Kitching --- firmware/2lib/include/2common.h | 7 +++++++ firmware/lib/cgptlib/cgptlib.c | 2 +- firmware/lib/vboot_ui_legacy_clamshell.c | 2 +- firmware/lib/vboot_ui_legacy_wilco.c | 2 +- futility/cmd_dump_fmap.c | 4 ++-- futility/cmd_sign.c | 2 +- host/lib/crossystem.c | 2 +- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/firmware/2lib/include/2common.h b/firmware/2lib/include/2common.h index dbc62643..0d66458f 100644 --- a/firmware/2lib/include/2common.h +++ b/firmware/2lib/include/2common.h @@ -84,6 +84,13 @@ struct vb2_public_key; #endif #endif +#if (defined(__GNUC__) && __GNUC__ >= 7) || \ + (defined(__clang__) && __has_attribute(fallthrough)) +#define VBOOT_FALLTHROUGH __attribute__((fallthrough)) +#else +#define VBOOT_FALLTHROUGH ((void)0) +#endif + /** * Round up a number to a multiple of VB2_WORKBUF_ALIGN * diff --git a/firmware/lib/cgptlib/cgptlib.c b/firmware/lib/cgptlib/cgptlib.c index 3fbb2fdc..4c091d04 100644 --- a/firmware/lib/cgptlib/cgptlib.c +++ b/firmware/lib/cgptlib/cgptlib.c @@ -142,7 +142,7 @@ int GptUpdateKernelWithEntry(GptData *gpt, GptEntry *e, uint32_t update_type) break; } /* Out of tries, so drop through and mark partition bad. */ - __attribute__ ((fallthrough)); + VBOOT_FALLTHROUGH; } case GPT_UPDATE_ENTRY_BAD: { /* Giving up on this partition entirely. */ diff --git a/firmware/lib/vboot_ui_legacy_clamshell.c b/firmware/lib/vboot_ui_legacy_clamshell.c index a1ffe5b0..027b49ea 100644 --- a/firmware/lib/vboot_ui_legacy_clamshell.c +++ b/firmware/lib/vboot_ui_legacy_clamshell.c @@ -295,7 +295,7 @@ static vb2_error_t vb2_developer_ui(struct vb2_context *ctx) /* Only disable virtual dev switch if allowed by GBB */ if (!(gbb->flags & VB2_GBB_FLAG_ENTER_TRIGGERS_TONORM)) break; - __attribute__ ((fallthrough)); + VBOOT_FALLTHROUGH; case ' ': /* See if we should disable virtual dev-mode switch. */ VB2_DEBUG("sd->flags=%#x\n", sd->flags); diff --git a/firmware/lib/vboot_ui_legacy_wilco.c b/firmware/lib/vboot_ui_legacy_wilco.c index 59a49684..7838bcfe 100644 --- a/firmware/lib/vboot_ui_legacy_wilco.c +++ b/firmware/lib/vboot_ui_legacy_wilco.c @@ -67,7 +67,7 @@ static vb2_error_t vb2_enter_vendor_data_ui(struct vb2_context *ctx, return VB2_SUCCESS; case 'a'...'z': key = toupper(key); - __attribute__ ((fallthrough)); + VBOOT_FALLTHROUGH; case '0'...'9': case 'A'...'Z': if ((len > 0 && is_vowel(key)) || diff --git a/futility/cmd_dump_fmap.c b/futility/cmd_dump_fmap.c index ff7252c6..3a0e14ed 100644 --- a/futility/cmd_dump_fmap.c +++ b/futility/cmd_dump_fmap.c @@ -445,7 +445,7 @@ static int do_dump_fmap(int argc, char *argv[]) break; case 'H': opt_gaps = 1; - __attribute__ ((fallthrough)); + VBOOT_FALLTHROUGH; case 'h': opt_format = FMT_HUMAN; opt_overlap++; @@ -508,7 +508,7 @@ static int do_dump_fmap(int argc, char *argv[]) case FMT_NORMAL: printf("hit at 0x%08x\n", (uint32_t) ((char *)fmap - (char *)base_of_rom)); - __attribute__ ((fallthrough)); + VBOOT_FALLTHROUGH; default: retval = normal_fmap(fmap, argc - optind - 1, diff --git a/futility/cmd_sign.c b/futility/cmd_sign.c index c95b8c97..6243e3a8 100644 --- a/futility/cmd_sign.c +++ b/futility/cmd_sign.c @@ -722,7 +722,7 @@ static int do_sign(int argc, char *argv[]) break; case OPT_FV: sign_option.fv_specified = 1; - __attribute__ ((fallthrough)); + VBOOT_FALLTHROUGH; case OPT_INFILE: sign_option.inout_file_count++; infile = optarg; diff --git a/host/lib/crossystem.c b/host/lib/crossystem.c index 25a55d82..bb10c399 100644 --- a/host/lib/crossystem.c +++ b/host/lib/crossystem.c @@ -313,7 +313,7 @@ static int GetVdatInt(VdatIntField field) break; case VDAT_INT_FW_BOOT2: value = (sh->flags & VBSD_BOOT_FIRMWARE_VBOOT2 ? 1 : 0); - __attribute__ ((fallthrough)); + VBOOT_FALLTHROUGH; default: break; }