From ac77140b7f4f42075d2377fc9d956a636b05aacf Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Mon, 11 Mar 2019 16:07:55 -0700 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/1518660 Reviewed-by: Daisuke Nojiri --- core/cortex-m/task.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'core/cortex-m/task.c') 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); -- cgit v1.2.1