diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2019-03-11 16:07:55 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-03-26 04:42:56 -0700 |
commit | ac77140b7f4f42075d2377fc9d956a636b05aacf (patch) | |
tree | c64c6a30916ff741a2ab235141f7bd071cd54483 /core | |
parent | bb266fc26fc05d4ab22de6ad7bce5b477c9f9140 (diff) | |
download | chrome-ec-ac77140b7f4f42075d2377fc9d956a636b05aacf.tar.gz |
common: bit change 1 << constants with BIT(constants)
Mechanical replacement of bit operation where operand is a constant.
More bit operation exist, but prone to errors.
Reveal a bug in npcx:
chip/npcx/system-npcx7.c:114:54: error: conversion from 'long unsigned int' to 'uint8_t' {aka 'volatile unsigned char'} changes value from '16777215' to '255' [-Werror=overflow]
BUG=None
BRANCH=None
TEST=None
Change-Id: I006614026143fa180702ac0d1cc2ceb1b3c6eeb0
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1518660
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/cortex-m/mpu.c | 2 | ||||
-rw-r--r-- | core/cortex-m/panic.c | 4 | ||||
-rw-r--r-- | core/cortex-m/task.c | 10 | ||||
-rw-r--r-- | core/cortex-m0/task.c | 8 | ||||
-rw-r--r-- | core/minute-ia/interrupts.c | 2 | ||||
-rw-r--r-- | core/minute-ia/task.c | 8 | ||||
-rw-r--r-- | core/nds32/task.c | 8 |
7 files changed, 21 insertions, 21 deletions
diff --git a/core/cortex-m/mpu.c b/core/cortex-m/mpu.c index 795f809eca..8376a00b32 100644 --- a/core/cortex-m/mpu.c +++ b/core/cortex-m/mpu.c @@ -95,7 +95,7 @@ static int mpu_config_region(uint8_t region, uint32_t addr, uint32_t size, blocks = size >> (size_bit - 2); /* Represent occupied blocks of two regions with srd mask. */ - srd1 = (1 << blocks) - 1; + srd1 = BIT(blocks) - 1; srd2 = (1 << ((size >> (size_bit - 5)) & 0x7)) - 1; /* diff --git a/core/cortex-m/panic.c b/core/cortex-m/panic.c index f5a8f23c5c..219920463f 100644 --- a/core/cortex-m/panic.c +++ b/core/cortex-m/panic.c @@ -156,7 +156,7 @@ static void show_fault(uint32_t mmfs, uint32_t hfsr, uint32_t dfsr) int count = 0; for (upto = 0; upto < 32; upto++) { - if ((mmfs & (1 << upto)) && mmfs_name[upto]) { + if ((mmfs & BIT(upto)) && mmfs_name[upto]) { do_separate(&count); panic_puts(mmfs_name[upto]); } @@ -176,7 +176,7 @@ static void show_fault(uint32_t mmfs, uint32_t hfsr, uint32_t dfsr) } for (upto = 0; upto < 5; upto++) { - if ((dfsr & (1 << upto))) { + if ((dfsr & BIT(upto))) { do_separate(&count); panic_puts(dfsr_name[upto]); } diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c index 5ab3272141..91d0d56d90 100644 --- a/core/cortex-m/task.c +++ b/core/cortex-m/task.c @@ -164,7 +164,7 @@ static uint32_t task_reset_state[TASK_ID_COUNT] = { /* Sanity checks about static task invariants */ BUILD_ASSERT(TASK_ID_COUNT <= sizeof(unsigned) * 8); BUILD_ASSERT(TASK_ID_COUNT < (1 << (sizeof(task_id_t) * 8))); -BUILD_ASSERT((1 << TASK_ID_COUNT) < TASK_RESET_LOCK); +BUILD_ASSERT(BIT(TASK_ID_COUNT) < TASK_RESET_LOCK); /* Stacks for all tasks */ #define TASK(n, r, d, s) + s @@ -202,13 +202,13 @@ static int need_resched_or_profiling; * can do their init within a task switching context. The hooks task will then * make a call to enable all tasks. */ -static uint32_t tasks_ready = (1 << TASK_ID_HOOKS); +static uint32_t tasks_ready = BIT(TASK_ID_HOOKS); /* * Initially allow only the HOOKS and IDLE task to run, regardless of ready * status, in order for HOOK_INIT to complete before other tasks. * task_enable_all_tasks() will open the flood gates. */ -static uint32_t tasks_enabled = (1 << TASK_ID_HOOKS) | (1 << TASK_ID_IDLE); +static uint32_t tasks_enabled = BIT(TASK_ID_HOOKS) | BIT(TASK_ID_IDLE); static int start_called; /* Has task swapping started */ @@ -486,7 +486,7 @@ uint32_t task_wait_event_mask(uint32_t event_mask, int timeout_us) void task_enable_all_tasks(void) { /* Mark all tasks as ready and able to run. */ - tasks_ready = tasks_enabled = (1 << TASK_ID_COUNT) - 1; + tasks_ready = tasks_enabled = BIT(TASK_ID_COUNT) - 1; /* Reschedule the highest priority task. */ __schedule(0, 0); } @@ -891,7 +891,7 @@ void mutex_unlock(struct mutex *mtx) while (waiters) { task_id_t id = __fls(waiters); - waiters &= ~(1 << id); + waiters &= ~BIT(id); /* Somebody is waiting on the mutex */ task_set_event(id, TASK_EVENT_MUTEX, 0); diff --git a/core/cortex-m0/task.c b/core/cortex-m0/task.c index 9b3f8ce0ed..e13cd39a58 100644 --- a/core/cortex-m0/task.c +++ b/core/cortex-m0/task.c @@ -136,13 +136,13 @@ task_ *current_task = (task_ *)scratchpad; * can do their init within a task switching context. The hooks task will then * make a call to enable all tasks. */ -static uint32_t tasks_ready = (1 << TASK_ID_HOOKS); +static uint32_t tasks_ready = BIT(TASK_ID_HOOKS); /* * Initially allow only the HOOKS and IDLE task to run, regardless of ready * status, in order for HOOK_INIT to complete before other tasks. * task_enable_all_tasks() will open the flood gates. */ -static uint32_t tasks_enabled = (1 << TASK_ID_HOOKS) | (1 << TASK_ID_IDLE); +static uint32_t tasks_enabled = BIT(TASK_ID_HOOKS) | BIT(TASK_ID_IDLE); static int start_called; /* Has task swapping started */ @@ -428,7 +428,7 @@ uint32_t task_wait_event_mask(uint32_t event_mask, int timeout_us) void task_enable_all_tasks(void) { /* Mark all tasks as ready and able to run. */ - tasks_ready = tasks_enabled = (1 << TASK_ID_COUNT) - 1; + tasks_ready = tasks_enabled = BIT(TASK_ID_COUNT) - 1; /* Reschedule the highest priority task. */ __schedule(0, 0); } @@ -526,7 +526,7 @@ void mutex_unlock(struct mutex *mtx) while (waiters) { task_id_t id = __fls(waiters); - waiters &= ~(1 << id); + waiters &= ~BIT(id); /* Somebody is waiting on the mutex */ task_set_event(id, TASK_EVENT_MUTEX, 0); diff --git a/core/minute-ia/interrupts.c b/core/minute-ia/interrupts.c index 96e5626d47..98c6c3509d 100644 --- a/core/minute-ia/interrupts.c +++ b/core/minute-ia/interrupts.c @@ -215,7 +215,7 @@ static inline unsigned int lapic_get_vector(uint32_t reg_base, uint32_t vector) uint32_t reg_pos = (vector >> 5) << 4; uint32_t vec_pos = vector & (32 - 1); - return REG32(reg_base + reg_pos) & (1 << vec_pos); + return REG32(reg_base + reg_pos) & BIT(vec_pos); } /* diff --git a/core/minute-ia/task.c b/core/minute-ia/task.c index 62481d96f0..601451d6df 100644 --- a/core/minute-ia/task.c +++ b/core/minute-ia/task.c @@ -136,13 +136,13 @@ task_ *current_task, *next_task; * can do their init within a task switching context. The hooks task will then * make a call to enable all tasks. */ -static uint32_t tasks_ready = (1 << TASK_ID_HOOKS); +static uint32_t tasks_ready = BIT(TASK_ID_HOOKS); /* * Initially allow only the HOOKS and IDLE task to run, regardless of ready * status, in order for HOOK_INIT to complete before other tasks. * task_enable_all_tasks() will open the flood gates. */ -static uint32_t tasks_enabled = (1 << TASK_ID_HOOKS) | (1 << TASK_ID_IDLE); +static uint32_t tasks_enabled = BIT(TASK_ID_HOOKS) | BIT(TASK_ID_IDLE); static int start_called; /* Has task swapping started */ @@ -393,7 +393,7 @@ uint32_t task_wait_event_mask(uint32_t event_mask, int timeout_us) void task_enable_all_tasks(void) { /* Mark all tasks as ready and table to run. */ - tasks_ready = tasks_enabled = (1 << TASK_ID_COUNT) - 1; + tasks_ready = tasks_enabled = BIT(TASK_ID_COUNT) - 1; /* Reschedule the highest priority task. */ __schedule(0, 0); @@ -464,7 +464,7 @@ void mutex_unlock(struct mutex *mtx) while (waiters) { task_id_t id = __fls(waiters); - waiters &= ~(1 << id); + waiters &= ~BIT(id); /* Somebody is waiting on the mutex */ task_set_event(id, TASK_EVENT_MUTEX, 0); diff --git a/core/nds32/task.c b/core/nds32/task.c index 7cd9049733..ac3fcb0b0c 100644 --- a/core/nds32/task.c +++ b/core/nds32/task.c @@ -158,13 +158,13 @@ int need_resched; * can do their init within a task switching context. The hooks task will then * make a call to enable all tasks. */ -static uint32_t tasks_ready = (1 << TASK_ID_HOOKS); +static uint32_t tasks_ready = BIT(TASK_ID_HOOKS); /* * Initially allow only the HOOKS and IDLE task to run, regardless of ready * status, in order for HOOK_INIT to complete before other tasks. * task_enable_all_tasks() will open the flood gates. */ -static uint32_t tasks_enabled = (1 << TASK_ID_HOOKS) | (1 << TASK_ID_IDLE); +static uint32_t tasks_enabled = BIT(TASK_ID_HOOKS) | BIT(TASK_ID_IDLE); int start_called; /* Has task swapping started */ @@ -544,7 +544,7 @@ void set_int_ctrl(uint32_t val) void task_enable_all_tasks(void) { /* Mark all tasks as ready and able to run. */ - tasks_ready = tasks_enabled = (1 << TASK_ID_COUNT) - 1; + tasks_ready = tasks_enabled = BIT(TASK_ID_COUNT) - 1; /* Reschedule the highest priority task. */ __schedule(0, 0, 0); } @@ -656,7 +656,7 @@ void __ram_code mutex_unlock(struct mutex *mtx) while (waiters) { task_id_t id = __fls(waiters); - waiters &= ~(1 << id); + waiters &= ~BIT(id); /* Somebody is waiting on the mutex */ task_set_event(id, TASK_EVENT_MUTEX, 0); |