diff options
author | Dawid Niedzwiecki <dn@semihalf.com> | 2021-12-09 15:09:09 +0100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-12-17 08:04:58 +0000 |
commit | c346481f4bcc5aa52662e4dffa2c17d7b5b18509 (patch) | |
tree | be00d40db66c9887a5f9c9882dc10277089bba39 | |
parent | 9b972a0f21c95d49ffbe2e42adb7400714eda516 (diff) | |
download | chrome-ec-c346481f4bcc5aa52662e4dffa2c17d7b5b18509.tar.gz |
atomic: cast to unsigned when shifting
Since atomic_t is a signed type, cast the atomic variable to an unsigned
type when it is used around shifting, because it is safer and not
implementation-dependent.
BUG=b:207082842
TEST=make buildall && zmake testall
BRANCH=main
Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com>
Change-Id: I58011b3217bbe03d85ecac40adfa3723a76f18e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3330200
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Commit-Queue: Dawid Niedzwiecki <dawidn@google.com>
-rw-r--r-- | common/button.c | 5 | ||||
-rw-r--r-- | common/usbc/usb_pd_dpm.c | 6 | ||||
-rw-r--r-- | common/usbc_ocp.c | 2 |
3 files changed, 7 insertions, 6 deletions
diff --git a/common/button.c b/common/button.c index e63fdb8103..145cd9db74 100644 --- a/common/button.c +++ b/common/button.c @@ -62,7 +62,7 @@ static atomic_t sim_button_state; */ static int simulated_button_pressed(const struct button_config *button) { - return !!(sim_button_state & BIT(button->type)); + return !!((uint32_t)sim_button_state & BIT(button->type)); } #endif @@ -389,7 +389,8 @@ static void simulate_button_release_deferred(void) /* Release the button */ for (button_idx = 0; button_idx < BUTTON_COUNT; button_idx++) { /* Check state for button pressed */ - if (sim_button_state & BIT(buttons[button_idx].type)) { + if ((uint32_t)sim_button_state & + BIT(buttons[button_idx].type)) { /* Set state of the button as released */ atomic_clear_bits(&sim_button_state, BIT(buttons[button_idx].type)); diff --git a/common/usbc/usb_pd_dpm.c b/common/usbc/usb_pd_dpm.c index 4290d96e9b..5deea53d5d 100644 --- a/common/usbc/usb_pd_dpm.c +++ b/common/usbc/usb_pd_dpm.c @@ -708,8 +708,8 @@ void dpm_remove_sink(int port) if (CONFIG_USB_PD_3A_PORTS == 0) return; - if (!(BIT(port) & sink_max_pdo_requested) && - !(BIT(port) & non_pd_sink_max_requested)) + if (!(BIT(port) & (uint32_t)sink_max_pdo_requested) && + !(BIT(port) & (uint32_t)non_pd_sink_max_requested)) return; atomic_clear_bits(&sink_max_pdo_requested, BIT(port)); @@ -730,7 +730,7 @@ void dpm_remove_source(int port) if (!IS_ENABLED(CONFIG_USB_PD_FRS)) return; - if (!(BIT(port) & source_frs_max_requested)) + if (!(BIT(port) & (uint32_t)source_frs_max_requested)) return; atomic_clear_bits(&source_frs_max_requested, BIT(port)); diff --git a/common/usbc_ocp.c b/common/usbc_ocp.c index 2654993576..c7c977bf12 100644 --- a/common/usbc_ocp.c +++ b/common/usbc_ocp.c @@ -53,7 +53,7 @@ static void clear_oc_tbl(void) * Only clear the table if the port partner is no longer * attached after debouncing. */ - if ((!(BIT(port) & snk_connected_ports)) && + if ((!(BIT(port) & (uint32_t)snk_connected_ports)) && oc_event_cnt_tbl[port]) { oc_event_cnt_tbl[port] = 0; CPRINTS("C%d: OC events cleared", port); |