kernel: Fix bitwise operators with unsigned operators
Bitwise operators should be used only with unsigned integer operands because the result os bitwise operations on signed integers are implementation-defined. Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
parent
0866d18d03
commit
8aec087268
6 changed files with 29 additions and 12 deletions
|
@ -31,6 +31,7 @@
|
|||
#include <asm_inline.h>
|
||||
#include <exception.h>
|
||||
#include <kernel_arch_thread.h>
|
||||
#include <misc/util.h>
|
||||
|
||||
#ifndef _ASMLANGUAGE
|
||||
#include <kernel.h>
|
||||
|
|
|
@ -658,13 +658,13 @@ extern void k_thread_foreach(k_thread_user_cb_t user_cb, void *user_data);
|
|||
* @brief system thread that must not abort
|
||||
* @req K-THREAD-000
|
||||
* */
|
||||
#define K_ESSENTIAL (1 << 0)
|
||||
#define K_ESSENTIAL (BIT(0))
|
||||
|
||||
#if defined(CONFIG_FP_SHARING)
|
||||
/**
|
||||
* @brief thread uses floating point registers
|
||||
*/
|
||||
#define K_FP_REGS (1 << 1)
|
||||
#define K_FP_REGS (BIT(1))
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -673,7 +673,7 @@ extern void k_thread_foreach(k_thread_user_cb_t user_cb, void *user_data);
|
|||
* This thread has dropped from supervisor mode to user mode and consequently
|
||||
* has additional restrictions
|
||||
*/
|
||||
#define K_USER (1 << 2)
|
||||
#define K_USER (BIT(2))
|
||||
|
||||
/**
|
||||
* @brief Inherit Permissions
|
||||
|
@ -683,14 +683,14 @@ extern void k_thread_foreach(k_thread_user_cb_t user_cb, void *user_data);
|
|||
* permissions from the thread that created it. No effect if CONFIG_USERSPACE
|
||||
* is not enabled.
|
||||
*/
|
||||
#define K_INHERIT_PERMS (1 << 3)
|
||||
#define K_INHERIT_PERMS (BIT(3))
|
||||
|
||||
#ifdef CONFIG_X86
|
||||
/* x86 Bitmask definitions for threads user options */
|
||||
|
||||
#if defined(CONFIG_FP_SHARING) && defined(CONFIG_SSE)
|
||||
/* thread uses SSEx (and also FP) registers */
|
||||
#define K_SSE_REGS (1 << 7)
|
||||
#define K_SSE_REGS (BIT(7))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -117,8 +117,12 @@ static inline s64_t arithmetic_shift_right(s64_t value, u8_t shift)
|
|||
#define MHZ(x) (KHZ(x) * 1000)
|
||||
|
||||
#ifndef BIT
|
||||
#if defined(_ASMLANGUAGE)
|
||||
#define BIT(n) (1 << (n))
|
||||
#else
|
||||
#define BIT(n) (1UL << (n))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define BIT_MASK(n) (BIT(n) - 1)
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <atomic.h>
|
||||
#include <misc/dlist.h>
|
||||
#include <misc/rb.h>
|
||||
#include <misc/util.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
|
@ -31,22 +32,22 @@
|
|||
/* states: common uses low bits, arch-specific use high bits */
|
||||
|
||||
/* Not a real thread */
|
||||
#define _THREAD_DUMMY (1 << 0)
|
||||
#define _THREAD_DUMMY (BIT(0))
|
||||
|
||||
/* Thread is waiting on an object */
|
||||
#define _THREAD_PENDING (1 << 1)
|
||||
#define _THREAD_PENDING (BIT(1))
|
||||
|
||||
/* Thread has not yet started */
|
||||
#define _THREAD_PRESTART (1 << 2)
|
||||
#define _THREAD_PRESTART (BIT(2))
|
||||
|
||||
/* Thread has terminated */
|
||||
#define _THREAD_DEAD (1 << 3)
|
||||
#define _THREAD_DEAD (BIT(3))
|
||||
|
||||
/* Thread is suspended */
|
||||
#define _THREAD_SUSPENDED (1 << 4)
|
||||
#define _THREAD_SUSPENDED (BIT(4))
|
||||
|
||||
/* Thread is present in the ready queue */
|
||||
#define _THREAD_QUEUED (1 << 6)
|
||||
#define _THREAD_QUEUED (BIT(6))
|
||||
|
||||
/* end - states */
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <syscall_handler.h>
|
||||
#include <misc/slist.h>
|
||||
#include <misc/dlist.h>
|
||||
#include <misc/util.h>
|
||||
#include <misc/__assert.h>
|
||||
|
||||
void k_poll_event_init(struct k_poll_event *event, u32_t type,
|
||||
|
@ -29,7 +30,7 @@ void k_poll_event_init(struct k_poll_event *event, u32_t type,
|
|||
{
|
||||
__ASSERT(mode == K_POLL_MODE_NOTIFY_ONLY,
|
||||
"only NOTIFY_ONLY mode is supported\n");
|
||||
__ASSERT(type < (1 << _POLL_NUM_TYPES), "invalid type\n");
|
||||
__ASSERT(type < (BIT(_POLL_NUM_TYPES)), "invalid type\n");
|
||||
__ASSERT(obj, "must provide an object\n");
|
||||
|
||||
event->poller = NULL;
|
||||
|
|
10
scripts/coccinelle/unsigned_shift.cocci
Normal file
10
scripts/coccinelle/unsigned_shift.cocci
Normal file
|
@ -0,0 +1,10 @@
|
|||
// Copyright (c) 2017 Intel Corporation
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
@@
|
||||
constant A;
|
||||
@@
|
||||
|
||||
- 1 << A
|
||||
+ BIT(A)
|
Loading…
Add table
Add a link
Reference in a new issue