Skip to content
Permalink
Browse files

irq: Fix irq_lock api usage

irq_lock returns an unsigned int, though, several places was using
signed int. This commit fix this behaviour.

In order to avoid this error happens again, a coccinelle script was
added and can be used to check violations.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
  • Loading branch information...
ceolin authored and nashif committed Aug 15, 2018
1 parent ec462f8 commit 0866d18d03c4c641bed0a81cf6d7acbcc31bb98e
Showing with 124 additions and 73 deletions.
  1. +3 −3 arch/arc/core/irq_manage.c
  2. +1 −1 arch/arc/core/irq_offload.c
  3. +1 −1 arch/arm/core/irq_manage.c
  4. +1 −1 arch/arm/soc/nxp_imx/mcimx6x_m4/soc.c
  5. +1 −1 arch/arm/soc/nxp_imx/rt/soc.c
  6. +1 −1 arch/arm/soc/nxp_kinetis/k6x/soc.c
  7. +1 −1 arch/arm/soc/nxp_kinetis/kl2x/soc.c
  8. +1 −1 arch/arm/soc/nxp_kinetis/kwx/soc_kw2xd.c
  9. +1 −1 arch/arm/soc/nxp_kinetis/kwx/soc_kw4xz.c
  10. +1 −1 arch/arm/soc/nxp_lpc/lpc54xxx/soc.c
  11. +1 −1 arch/arm/soc/silabs_exx32/efm32wg/soc.c
  12. +1 −1 arch/arm/soc/silabs_exx32/efr32fg1p/soc.c
  13. +2 −2 arch/nios2/core/irq_manage.c
  14. +1 −1 arch/nios2/core/irq_offload.c
  15. +1 −1 arch/riscv32/core/irq_offload.c
  16. +2 −2 arch/riscv32/soc/pulpino/pulpino_irq.c
  17. +1 −1 arch/x86/core/irq_offload.c
  18. +1 −1 drivers/console/telnet_console.c
  19. +1 −1 drivers/console/websocket_console.c
  20. +2 −2 drivers/flash/soc_flash_mcux.c
  21. +1 −1 drivers/gpio/gpio_esp32.c
  22. +2 −2 drivers/i2c/i2c_esp32.c
  23. +2 −2 drivers/interrupt_controller/ioapic_intr.c
  24. +3 −3 drivers/interrupt_controller/loapic_intr.c
  25. +2 −2 drivers/interrupt_controller/mvic.c
  26. +1 −1 drivers/ipm/ipm_mcux.c
  27. +1 −1 drivers/ipm/ipm_quark_se.c
  28. +1 −1 drivers/serial/uart_imx.c
  29. +1 −1 drivers/serial/uart_ns16550.c
  30. +3 −3 drivers/timer/xtensa_sys_timer.c
  31. +3 −2 kernel/mutex.c
  32. +2 −2 kernel/sched.c
  33. +2 −2 kernel/smp.c
  34. +2 −2 kernel/thread.c
  35. +1 −1 kernel/timer.c
  36. +12 −10 kernel/userspace.c
  37. +2 −2 kernel/work_q.c
  38. +47 −0 scripts/coccinelle/irq_lock.cocci
  39. +1 −1 subsys/net/ip/tcp.c
  40. +1 −1 subsys/net/l2/ethernet/gptp/gptp.c
  41. +1 −1 subsys/usb/usb_device.c
  42. +3 −3 tests/kernel/fatal/src/main.c
  43. +1 −1 tests/kernel/obj_tracing/src/main.c
  44. +1 −1 tests/kernel/pending/src/main.c
  45. +3 −2 tests/subsys/logging/logger-hook/src/main.c
@@ -38,7 +38,7 @@

void _arch_irq_enable(unsigned int irq)
{
int key = irq_lock();
unsigned int key = irq_lock();

_arc_v2_irq_unit_int_enable(irq);
irq_unlock(key);
@@ -55,7 +55,7 @@ void _arch_irq_enable(unsigned int irq)

void _arch_irq_disable(unsigned int irq)
{
int key = irq_lock();
unsigned int key = irq_lock();

_arc_v2_irq_unit_int_disable(irq);
irq_unlock(key);
@@ -79,7 +79,7 @@ void _irq_priority_set(unsigned int irq, unsigned int prio, u32_t flags)
{
ARG_UNUSED(flags);

int key = irq_lock();
unsigned int key = irq_lock();

__ASSERT(prio < CONFIG_NUM_IRQ_PRIO_LEVELS,
"invalid priority %d for irq %d", prio, irq);
@@ -22,7 +22,7 @@ void _irq_do_offload(void)

void irq_offload(irq_offload_routine_t routine, void *parameter)
{
int key;
unsigned int key;

key = irq_lock();
offload_routine = routine;
@@ -146,7 +146,7 @@ void _irq_spurious(void *unused)
void _arch_isr_direct_pm(void)
{
#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE)
int key;
unsigned int key;

/* irq_lock() does what we wan for this CPU */
key = irq_lock();
@@ -143,7 +143,7 @@ static int mcimx6x_m4_init(struct device *arg)
{
ARG_UNUSED(arg);

int oldLevel; /* Old interrupt lock level */
unsigned int oldLevel; /* Old interrupt lock level */

/* Disable interrupts */
oldLevel = irq_lock();
@@ -111,7 +111,7 @@ static int imxrt_init(struct device *arg)
{
ARG_UNUSED(arg);

int oldLevel; /* old interrupt lock level */
unsigned int oldLevel; /* old interrupt lock level */

/* disable interrupts */
oldLevel = irq_lock();
@@ -156,7 +156,7 @@ static int fsl_frdm_k64f_init(struct device *arg)
{
ARG_UNUSED(arg);

int oldLevel; /* old interrupt lock level */
unsigned int oldLevel; /* old interrupt lock level */
#if !defined(CONFIG_HAS_SYSMPU)
u32_t temp_reg;
#endif /* !CONFIG_HAS_SYSMPU */
@@ -108,7 +108,7 @@ static int kl2x_init(struct device *arg)
{
ARG_UNUSED(arg);

int oldLevel; /* old interrupt lock level */
unsigned int oldLevel; /* old interrupt lock level */

/* disable interrupts */
oldLevel = irq_lock();
@@ -181,7 +181,7 @@ static int kw2xd_init(struct device *arg)
{
ARG_UNUSED(arg);

int oldLevel; /* old interrupt lock level */
unsigned int oldLevel; /* old interrupt lock level */

/* disable interrupts */
oldLevel = irq_lock();
@@ -107,7 +107,7 @@ static int kwx_init(struct device *arg)
{
ARG_UNUSED(arg);

int oldLevel; /* old interrupt lock level */
unsigned int oldLevel; /* old interrupt lock level */

/* disable interrupts */
oldLevel = irq_lock();
@@ -82,7 +82,7 @@ static int nxp_lpc54114_init(struct device *arg)
ARG_UNUSED(arg);

/* old interrupt lock level */
int oldLevel;
unsigned int oldLevel;

/* disable interrupts */
oldLevel = irq_lock();
@@ -78,7 +78,7 @@ static int silabs_efm32wg_init(struct device *arg)
{
ARG_UNUSED(arg);

int oldLevel; /* old interrupt lock level */
unsigned int oldLevel; /* old interrupt lock level */

/* disable interrupts */
oldLevel = irq_lock();
@@ -78,7 +78,7 @@ static int silabs_efr32fg1p_init(struct device *arg)
{
ARG_UNUSED(arg);

int oldLevel; /* old interrupt lock level */
unsigned int oldLevel; /* old interrupt lock level */

/* disable interrupts */
oldLevel = irq_lock();
@@ -33,7 +33,7 @@ void _irq_spurious(void *unused)
void _arch_irq_enable(unsigned int irq)
{
u32_t ienable;
int key;
unsigned int key;

key = irq_lock();

@@ -49,7 +49,7 @@ void _arch_irq_enable(unsigned int irq)
void _arch_irq_disable(unsigned int irq)
{
u32_t ienable;
int key;
unsigned int key;

key = irq_lock();

@@ -31,7 +31,7 @@ void _irq_do_offload(void)

void irq_offload(irq_offload_routine_t routine, void *parameter)
{
int key;
unsigned int key;

key = irq_lock();
_offload_routine = routine;
@@ -32,7 +32,7 @@ void _irq_do_offload(void)

void irq_offload(irq_offload_routine_t routine, void *parameter)
{
int key;
unsigned int key;

key = irq_lock();
_offload_routine = routine;
@@ -13,7 +13,7 @@

void _arch_irq_enable(unsigned int irq)
{
int key;
unsigned int key;

key = irq_lock();
/*
@@ -28,7 +28,7 @@ void _arch_irq_enable(unsigned int irq)

void _arch_irq_disable(unsigned int irq)
{
int key;
unsigned int key;

key = irq_lock();
PULP_IER &= ~(1 << irq);
@@ -27,7 +27,7 @@ void _irq_do_offload(void)

void irq_offload(irq_offload_routine_t routine, void *parameter)
{
int key;
unsigned int key;

/*
* Lock interrupts here to prevent any concurrency issues with
@@ -183,7 +183,7 @@ static inline struct line_buf *telnet_rb_get_line_in(void)
/* The actual printk hook */
static int telnet_console_out(int c)
{
int key = irq_lock();
unsigned int key = irq_lock();
struct line_buf *lb = telnet_rb_get_line_in();
bool yield = false;

@@ -169,7 +169,7 @@ static inline struct line_buf *ws_rb_get_line_in(void)
/* The actual printk hook */
static int ws_console_out(int c)
{
int key = irq_lock();
unsigned int key = irq_lock();
struct line_buf *lb = ws_rb_get_line_in();
bool yield = false;

@@ -39,7 +39,7 @@ static int flash_mcux_erase(struct device *dev, off_t offset, size_t len)
struct flash_priv *priv = dev->driver_data;
u32_t addr;
status_t rc;
int key;
unsigned int key;

if (k_sem_take(&priv->write_lock, K_NO_WAIT)) {
return -EACCES;
@@ -80,7 +80,7 @@ static int flash_mcux_write(struct device *dev, off_t offset,
struct flash_priv *priv = dev->driver_data;
u32_t addr;
status_t rc;
int key;
unsigned int key;

if (k_sem_take(&priv->write_lock, K_NO_WAIT)) {
return -EACCES;
@@ -86,7 +86,7 @@ static int config_interrupt(u32_t pin, int flags)
volatile u32_t *reg = gpio_pin_reg(pin);
int type = convert_int_type(flags);
u32_t v;
int key;
unsigned int key;

if (type < 0) {
return type;
@@ -169,7 +169,7 @@ static int i2c_esp32_configure(struct device *dev, u32_t dev_config)
{
const struct i2c_esp32_config *config = dev->config->config_info;
struct i2c_esp32_data *data = dev->driver_data;
int key = irq_lock();
unsigned int key = irq_lock();
u32_t v = 0;
int ret;

@@ -659,7 +659,7 @@ static int i2c_esp32_init(struct device *dev)
{
const struct i2c_esp32_config *config = dev->config->config_info;
struct i2c_esp32_data *data = dev->driver_data;
int key = irq_lock();
unsigned int key = irq_lock();

k_sem_init(&data->fifo_sem, 1, 1);
k_sem_init(&data->transfer_sem, 1, 1);
@@ -323,7 +323,7 @@ void _ioapic_int_vec_set(unsigned int irq, unsigned int vector)
static u32_t __IoApicGet(s32_t offset)
{
u32_t value; /* value */
int key; /* interrupt lock level */
unsigned int key; /* interrupt lock level */

/* lock interrupts to ensure indirect addressing works "atomically" */

@@ -350,7 +350,7 @@ static u32_t __IoApicGet(s32_t offset)
*/
static void __IoApicSet(s32_t offset, u32_t value)
{
int key; /* interrupt lock level */
unsigned int key; /* interrupt lock level */

/* lock interrupts to ensure indirect addressing works "atomically" */

@@ -297,7 +297,7 @@ void _loapic_int_vec_set(unsigned int irq, /* IRQ number of the interrupt */
unsigned int vector /* vector to copy into the LVT */
)
{
s32_t oldLevel; /* previous interrupt lock level */
unsigned int oldLevel; /* previous interrupt lock level */

/*
* The following mappings are used:
@@ -334,7 +334,7 @@ void _loapic_int_vec_set(unsigned int irq, /* IRQ number of the interrupt */

void _loapic_irq_enable(unsigned int irq)
{
s32_t oldLevel; /* previous interrupt lock level */
unsigned int oldLevel; /* previous interrupt lock level */

/*
* See the comments in _LoApicLvtVecSet() regarding IRQ to LVT mappings
@@ -363,7 +363,7 @@ void _loapic_irq_enable(unsigned int irq)

void _loapic_irq_disable(unsigned int irq)
{
s32_t oldLevel; /* previous interrupt lock level */
unsigned int oldLevel; /* previous interrupt lock level */

/*
* See the comments in _LoApicLvtVecSet() regarding IRQ to LVT mappings
@@ -64,7 +64,7 @@ static inline u32_t compute_ioregsel(unsigned int irq)
*/
static void _mvic_rte_set(unsigned int irq, u32_t value)
{
int key; /* interrupt lock level */
unsigned int key; /* interrupt lock level */
u32_t regsel;

__ASSERT(!(value & ~MVIC_IOWIN_SUPPORTED_BITS_MASK),
@@ -94,7 +94,7 @@ static void _mvic_rte_set(unsigned int irq, u32_t value)
*/
static void _mvic_rte_update(unsigned int irq, u32_t value, u32_t mask)
{
int key;
unsigned int key;
u32_t regsel, old_value, updated_value;

__ASSERT(!(value & ~MVIC_IOWIN_SUPPORTED_BITS_MASK),
@@ -70,7 +70,7 @@ static int mcux_mailbox_ipm_send(struct device *d, int wait, u32_t id,
u32_t data32[MCUX_IPM_DATA_REGS]; /* Until we change API
* to u32_t array
*/
int flags;
unsigned int flags;
int i;

ARG_UNUSED(wait);
@@ -97,7 +97,7 @@ static int quark_se_ipm_send(struct device *d, int wait, u32_t id,
const struct quark_se_ipm_config_info *config = d->config->config_info;
volatile struct quark_se_ipm *ipm = config->ipm;
u32_t data32[4]; /* Until we change API to u32_t array */
int flags;
unsigned int flags;
int i;

if (id > QUARK_SE_IPM_MAX_ID_VAL) {
@@ -55,7 +55,7 @@ static int uart_imx_init(struct device *dev)
{
UART_Type *uart = UART_STRUCT(dev);
const struct imx_uart_config *config = dev->config->config_info;
int old_level;
unsigned int old_level;

/* disable interrupts */
old_level = irq_lock();
@@ -310,7 +310,7 @@ static int uart_ns16550_init(struct device *dev)
{
struct uart_ns16550_dev_data_t * const dev_data = DEV_DATA(dev);

int old_level; /* old interrupt lock level */
unsigned int old_level; /* old interrupt lock level */
u8_t mdc = 0;

if (!ns16550_pci_uart_scan(dev)) {
@@ -162,7 +162,7 @@ static inline int32_t _get_max_clock_time(void)

static inline void _set_max_clock_time(void)
{
int key;
unsigned int key;

key = irq_lock();
_sys_clock_tick_count = _get_elapsed_clock_time();
@@ -181,7 +181,7 @@ void _set_time(u32_t time)
{
u32_t C; /* (current) time */
u32_t F; /* Time to program */
int key;
unsigned int key;

if (!time) {
idle_original_ticks = 0;
@@ -225,7 +225,7 @@ void _enable_sys_clock(void)
u64_t _get_elapsed_clock_time(void)
{
u32_t C;
int key;
unsigned int key;
u64_t total;
u32_t elapsed;

@@ -115,7 +115,8 @@ static void adjust_owner_prio(struct k_mutex *mutex, int new_prio)

int _impl_k_mutex_lock(struct k_mutex *mutex, s32_t timeout)
{
int new_prio, key;
int new_prio;
unsigned int key;

_sched_lock();

@@ -200,7 +201,7 @@ Z_SYSCALL_HANDLER(k_mutex_lock, mutex, timeout)

void _impl_k_mutex_unlock(struct k_mutex *mutex)
{
int key;
unsigned int key;

__ASSERT(mutex->lock_count > 0, "");
__ASSERT(mutex->owner == _current, "");
Oops, something went wrong.

0 comments on commit 0866d18

Please sign in to comment.
You can’t perform that action at this time.