diff options
author | Tom Hughes <tomhughes@chromium.org> | 2022-10-14 08:55:18 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-10-19 20:56:04 +0000 |
commit | 0d1b98c7183e8bc058a00ace0c30c1ea0e736a8a (patch) | |
tree | 6ff876b5578d5c83285dd90c295f0b697efc238c /zephyr/emul | |
parent | e66c6fe6efab16bed9b06c1b9e349c71eddb5a3f (diff) | |
download | chrome-ec-0d1b98c7183e8bc058a00ace0c30c1ea0e736a8a.tar.gz |
tree: Enable warning for fallthrough in switch statements
The EC code has generally been good about adding comments about
intentional fallthrough in switch statements, but there were a few cases
without comments (e.g., https://crrev.com/c/3949622). Enabling
-Wimplicit-fallthrough generates a compiler warning if the fallthrough
is not annotated with __attribute__((fallthrough)). For convenience, we
add a "__fallthrough" macro for this attribute.
See https://clang.llvm.org/docs/AttributeReference.html#fallthrough and
https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html.
BRANCH=none
BUG=b:253644823
TEST=make buildall
LOW_COVERAGE_REASON=legacy code
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Change-Id: I9f4d6049f4507a25ce706675d159b70e28b4b825
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3957420
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Diffstat (limited to 'zephyr/emul')
-rw-r--r-- | zephyr/emul/emul_sn5s330.c | 16 | ||||
-rw-r--r-- | zephyr/emul/tcpc/emul_ps8xxx.c | 6 | ||||
-rw-r--r-- | zephyr/emul/tcpc/emul_tcpci.c | 7 | ||||
-rw-r--r-- | zephyr/emul/tcpc/emul_tcpci_partner_common.c | 2 |
4 files changed, 19 insertions, 12 deletions
diff --git a/zephyr/emul/emul_sn5s330.c b/zephyr/emul/emul_sn5s330.c index f957cd9e05..6a520ed195 100644 --- a/zephyr/emul/emul_sn5s330.c +++ b/zephyr/emul/emul_sn5s330.c @@ -227,15 +227,15 @@ static int sn5s330_emul_write_byte(const struct emul *emul, int reg, /* Specially check for read-only reg */ switch (reg) { case SN5S330_INT_TRIP_RISE_REG1: - /* fallthrough */ + __fallthrough; case SN5S330_INT_TRIP_RISE_REG2: - /* fallthrough */ + __fallthrough; case SN5S330_INT_TRIP_RISE_REG3: - /* fallthrough */ + __fallthrough; case SN5S330_INT_TRIP_FALL_REG1: - /* fallthrough */ + __fallthrough; case SN5S330_INT_TRIP_FALL_REG2: - /* fallthrough */ + __fallthrough; case SN5S330_INT_TRIP_FALL_REG3: reg_to_write = sn5s330_emul_get_reg_ptr(data, reg); /* Clearing any bit deasserts /INT interrupt signal */ @@ -245,15 +245,15 @@ static int sn5s330_emul_write_byte(const struct emul *emul, int reg, *reg_to_write = val; break; case SN5S330_INT_STATUS_REG1: - /* fallthrough */ + __fallthrough; case SN5S330_INT_STATUS_REG2: - /* fallthrough */ + __fallthrough; case SN5S330_INT_STATUS_REG3: __ASSERT(false, "Write to an unverified-as-safe read-only register on " "0x%x", reg); - /* fallthrough for checkpath */ + __fallthrough; default: reg_to_write = sn5s330_emul_get_reg_ptr(data, reg); *reg_to_write = val; diff --git a/zephyr/emul/tcpc/emul_ps8xxx.c b/zephyr/emul/tcpc/emul_ps8xxx.c index 22972bf084..57cc2c85f5 100644 --- a/zephyr/emul/tcpc/emul_ps8xxx.c +++ b/zephyr/emul/tcpc/emul_ps8xxx.c @@ -235,6 +235,7 @@ static int ps8xxx_emul_tcpc_write_byte(const struct emul *emul, int reg, if (prod_id != PS8815_PRODUCT_ID) { break; } + __fallthrough; case PS8XXX_REG_I2C_DEBUGGING_ENABLE: case PS8XXX_REG_MUX_IN_HPD_ASSERTION: case PS8XXX_REG_BIST_CONT_MODE_BYTE0: @@ -282,6 +283,7 @@ static int ps8xxx_emul_tcpc_finish_write(const struct emul *emul, int reg, if (prod_id != PS8815_PRODUCT_ID) { break; } + __fallthrough; case PS8XXX_REG_I2C_DEBUGGING_ENABLE: case PS8XXX_REG_MUX_IN_HPD_ASSERTION: case PS8XXX_REG_BIST_CONT_MODE_BYTE0: @@ -399,11 +401,13 @@ static int ps8xxx_emul_read_byte_workhorse(const struct emul *emul, int reg, *val = data->dci_cfg; return 0; } + __fallthrough; case PS8XXX_EMUL_PORT_GPIO: if (reg == PS8805_REG_GPIO_CONTROL) { *val = data->gpio_ctrl; return 0; } + __fallthrough; case PS8XXX_EMUL_PORT_INVAL: LOG_ERR("Invalid I2C address"); return -EIO; @@ -481,11 +485,13 @@ static int ps8xxx_emul_write_byte_workhorse(const struct emul *emul, int reg, data->dci_cfg = val; return 0; } + __fallthrough; case PS8XXX_EMUL_PORT_GPIO: if (reg == PS8805_REG_GPIO_CONTROL) { data->gpio_ctrl = val; return 0; } + __fallthrough; case PS8XXX_EMUL_PORT_INVAL: LOG_ERR("Invalid I2C address"); return -EIO; diff --git a/zephyr/emul/tcpc/emul_tcpci.c b/zephyr/emul/tcpc/emul_tcpci.c index e19f7a2726..aa4e508489 100644 --- a/zephyr/emul/tcpc/emul_tcpci.c +++ b/zephyr/emul/tcpc/emul_tcpci.c @@ -1211,7 +1211,7 @@ static int tcpci_emul_handle_transmit(const struct emul *emul) case TCPCI_MSG_TX_HARD_RESET: tcpci_emul_disable_pd_msg_delivery(emul); tcpci_emul_reset_mask_regs(ctx); - /* fallthrough */ + __fallthrough; case TCPCI_MSG_CABLE_RESET: /* * Cable and Hard reset are special and set success and fail @@ -1259,13 +1259,13 @@ int tcpci_emul_handle_write(const struct emul *emul, int reg, int msg_len) ctx->write_data &= ~TCPC_REG_ALERT_RX_STATUS; } } - /* fallthrough */ + __fallthrough; case TCPC_REG_FAULT_STATUS: case TCPC_REG_ALERT_EXT: /* Clear bits where TCPM set 1 */ get_reg(ctx, reg, &alert_val); ctx->write_data = alert_val & (~ctx->write_data); - /* fallthrough */ + __fallthrough; case TCPC_REG_ALERT_MASK: case TCPC_REG_POWER_STATUS_MASK: case TCPC_REG_FAULT_STATUS_MASK: @@ -1344,6 +1344,7 @@ int tcpci_emul_handle_write(const struct emul *emul, int reg, int msg_len) switch (reg_bytes) { case 2: rsvd_mask = tcpci_emul_rsvd_mask[reg + 1]; + __fallthrough; case 1: rsvd_mask <<= 8; rsvd_mask |= tcpci_emul_rsvd_mask[reg]; diff --git a/zephyr/emul/tcpc/emul_tcpci_partner_common.c b/zephyr/emul/tcpc/emul_tcpci_partner_common.c index 1785acda51..22a9ddb91e 100644 --- a/zephyr/emul/tcpc/emul_tcpci_partner_common.c +++ b/zephyr/emul/tcpc/emul_tcpci_partner_common.c @@ -1076,7 +1076,7 @@ tcpci_partner_common_sop_msg_handler(struct tcpci_partner_data *data, tcpci_partner_common_clear_ams_ctrl_msg(data); - /* Fall through */ + __fallthrough; case PD_CTRL_ACCEPT: if (data->wait_for_response) { if (data->in_soft_reset) { |