Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coccinelle: standardize kernel timeout arguments #19562

Merged
merged 2 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/adc/adc_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static inline void adc_context_enable_timer(struct adc_context *ctx)
u32_t interval_us = ctx->options.interval_us;
u32_t interval_ms = ceiling_fraction(interval_us, 1000UL);

k_timer_start(&ctx->timer, 0, interval_ms);
k_timer_start(&ctx->timer, K_NO_WAIT, interval_ms);
}

static inline void adc_context_disable_timer(struct adc_context *ctx)
Expand Down
4 changes: 2 additions & 2 deletions drivers/ieee802154/ieee802154_cc1200.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,10 @@ static int cc1200_tx(struct device *dev,
}

/* Wait for SYNC to be sent */
k_sem_take(&cc1200->tx_sync, 100);
k_sem_take(&cc1200->tx_sync, K_MSEC(100));
if (atomic_get(&cc1200->tx_start) == 1) {
/* Now wait for the packet to be fully sent */
k_sem_take(&cc1200->tx_sync, 100);
k_sem_take(&cc1200->tx_sync, K_MSEC(100));
}

out:
Expand Down
2 changes: 1 addition & 1 deletion drivers/ieee802154/ieee802154_cc2520.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ static int cc2520_tx(struct device *dev,
goto error;
}

k_sem_take(&cc2520->tx_sync, 10);
k_sem_take(&cc2520->tx_sync, K_MSEC(10));

retry--;
status = verify_tx_done(cc2520);
Expand Down
2 changes: 1 addition & 1 deletion drivers/led/ht16k33.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ static int ht16k33_init(struct device *dev)

/* Setup timer for polling key data */
k_timer_init(&data->timer, ht16k33_timer_callback, NULL);
k_timer_start(&data->timer, 0,
k_timer_start(&data->timer, K_NO_WAIT,
CONFIG_HT16K33_KEYSCAN_POLL_MSEC);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/sensor/hp206c/hp206c.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static int hp206c_wait_dev_ready(struct device *dev, u32_t timeout_ms)
struct hp206c_device_data *hp206c = dev->driver_data;
u8_t int_src;

k_timer_start(&hp206c->tmr, timeout_ms, 0);
k_timer_start(&hp206c->tmr, timeout_ms, K_NO_WAIT);
k_timer_status_sync(&hp206c->tmr);

if (hp206c_read_reg(dev, HP206C_REG_INT_SRC, &int_src) < 0) {
Expand Down
3 changes: 2 additions & 1 deletion drivers/serial/uart_nrfx_uarte.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ static int uarte_nrfx_tx(struct device *dev, const u8_t *buf, size_t len,
nrf_uarte_tx_buffer_set(uarte, buf, len);
nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STARTTX);
if (data->uart_config.flow_ctrl == UART_CFG_FLOW_CTRL_RTS_CTS) {
k_timer_start(&data->async->tx_timeout_timer, timeout, 0);
k_timer_start(&data->async->tx_timeout_timer, timeout,
K_NO_WAIT);
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/device/usb_dc_kinetis.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ int usb_dc_ep_configure(const struct usb_dc_ep_cfg_data * const cfg)
(void)memset(&bdt[idx_even], 0, sizeof(struct buf_descriptor));
(void)memset(&bdt[idx_odd], 0, sizeof(struct buf_descriptor));

if (k_mem_pool_alloc(&ep_buf_pool, block, cfg->ep_mps * 2U, 10) == 0) {
if (k_mem_pool_alloc(&ep_buf_pool, block, cfg->ep_mps * 2U, K_MSEC(10)) == 0) {
(void)memset(block->data, 0, cfg->ep_mps * 2U);
} else {
LOG_ERR("Memory allocation time-out");
Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/device/usb_dc_mcux_ehci.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ int usb_dc_ep_configure(const struct usb_dc_ep_cfg_data *const cfg)
block->data = NULL;
}

if (k_mem_pool_alloc(&ep_buf_pool, block, cfg->ep_mps, 10) == 0) {
if (k_mem_pool_alloc(&ep_buf_pool, block, cfg->ep_mps, K_MSEC(10)) == 0) {
memset(block->data, 0, cfg->ep_mps);
} else {
LOG_ERR("Memory allocation time-out");
Expand Down
2 changes: 1 addition & 1 deletion drivers/wifi/eswifi/eswifi_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ static int eswifi_off_get(sa_family_t family,
k_sem_init(&socket->accept_sem, 1, 1);

k_delayed_work_submit_to_queue(&eswifi->work_q, &socket->read_work,
500);
K_MSEC(500));

unlock:
eswifi_unlock(eswifi);
Expand Down
2 changes: 1 addition & 1 deletion drivers/wifi/eswifi/eswifi_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static void eswifi_off_read_work(struct k_work *work)
done:
err = k_delayed_work_submit_to_queue(&eswifi->work_q,
&socket->read_work,
500);
K_MSEC(500));
if (err) {
LOG_ERR("Rescheduling socket read error");
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/wifi/eswifi/eswifi_socket_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ static int eswifi_socket_open(int family, int type, int proto)
socket->recv_data = socket;

k_delayed_work_submit_to_queue(&eswifi->work_q, &socket->read_work,
500);
K_MSEC(500));

unlock:
eswifi_unlock(eswifi);
Expand Down
2 changes: 1 addition & 1 deletion lib/cmsis_rtos_v1/cmsis_mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ osMutexId osMutexCreate(const osMutexDef_t *mutex_def)
return NULL;
}

if (k_mem_slab_alloc(&cmsis_mutex_slab, (void **)&mutex, 100) == 0) {
if (k_mem_slab_alloc(&cmsis_mutex_slab, (void **)&mutex, K_MSEC(100)) == 0) {
(void)memset(mutex, 0, sizeof(struct k_mutex));
} else {
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion lib/cmsis_rtos_v1/cmsis_semaphore.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ osSemaphoreId osSemaphoreCreate(const osSemaphoreDef_t *semaphore_def,
}

if (k_mem_slab_alloc(&cmsis_semaphore_slab,
(void **)&semaphore, 100) == 0) {
(void **)&semaphore, K_MSEC(100)) == 0) {
(void)memset(semaphore, 0, sizeof(struct k_sem));
} else {
return NULL;
Expand Down
6 changes: 3 additions & 3 deletions lib/cmsis_rtos_v1/cmsis_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ osTimerId osTimerCreate(const osTimerDef_t *timer_def, os_timer_type type,
return NULL;
}

if (k_mem_slab_alloc(&cmsis_timer_slab, (void **)&timer, 100) == 0) {
if (k_mem_slab_alloc(&cmsis_timer_slab, (void **)&timer, K_MSEC(100)) == 0) {
(void)memset(timer, 0, sizeof(struct timer_obj));
} else {
return NULL;
Expand Down Expand Up @@ -79,9 +79,9 @@ osStatus osTimerStart(osTimerId timer_id, uint32_t millisec)
}

if (timer->type == osTimerOnce) {
k_timer_start(&timer->ztimer, millisec, 0);
k_timer_start(&timer->ztimer, millisec, K_NO_WAIT);
} else if (timer->type == osTimerPeriodic) {
k_timer_start(&timer->ztimer, 0, millisec);
k_timer_start(&timer->ztimer, K_NO_WAIT, millisec);
}

timer->status = ACTIVE;
Expand Down
2 changes: 1 addition & 1 deletion lib/cmsis_rtos_v2/event_flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t *attr)
attr = &init_event_flags_attrs;
}

if (k_mem_slab_alloc(&cv2_event_flags_slab, (void **)&events, 100)
if (k_mem_slab_alloc(&cv2_event_flags_slab, (void **)&events, K_MSEC(100))
== 0) {
memset(events, 0, sizeof(struct cv2_event_flags));
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/cmsis_rtos_v2/mempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, uint32_t block_size,
attr = &init_mslab_attrs;
}

if (k_mem_slab_alloc(&cv2_mem_slab, (void **)&mslab, 100) == 0) {
if (k_mem_slab_alloc(&cv2_mem_slab, (void **)&mslab, K_MSEC(100)) == 0) {
(void)memset(mslab, 0, sizeof(struct cv2_mslab));
} else {
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion lib/cmsis_rtos_v2/msgq.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size,
attr = &init_msgq_attrs;
}

if (k_mem_slab_alloc(&cv2_msgq_slab, (void **)&msgq, 100) == 0) {
if (k_mem_slab_alloc(&cv2_msgq_slab, (void **)&msgq, K_MSEC(100)) == 0) {
(void)memset(msgq, 0, sizeof(struct cv2_msgq));
} else {
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion lib/cmsis_rtos_v2/mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ osMutexId_t osMutexNew(const osMutexAttr_t *attr)
__ASSERT(!(attr->attr_bits & osMutexRobust),
"Zephyr does not support osMutexRobust.\n");

if (k_mem_slab_alloc(&cv2_mutex_slab, (void **)&mutex, 100) == 0) {
if (k_mem_slab_alloc(&cv2_mutex_slab, (void **)&mutex, K_MSEC(100)) == 0) {
memset(mutex, 0, sizeof(struct cv2_mutex));
} else {
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion lib/cmsis_rtos_v2/semaphore.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count,
}

if (k_mem_slab_alloc(&cv2_semaphore_slab,
(void **)&semaphore, 100) == 0) {
(void **)&semaphore, K_MSEC(100)) == 0) {
(void)memset(semaphore, 0, sizeof(struct cv2_sem));
} else {
return NULL;
Expand Down
6 changes: 3 additions & 3 deletions lib/cmsis_rtos_v2/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type,
attr = &init_timer_attrs;
}

if (k_mem_slab_alloc(&cv2_timer_slab, (void **)&timer, 100) == 0) {
if (k_mem_slab_alloc(&cv2_timer_slab, (void **)&timer, K_MSEC(100)) == 0) {
(void)memset(timer, 0, sizeof(struct cv2_timer));
} else {
return NULL;
Expand Down Expand Up @@ -90,9 +90,9 @@ osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks)
}

if (timer->type == osTimerOnce) {
k_timer_start(&timer->z_timer, millisec, 0);
k_timer_start(&timer->z_timer, millisec, K_NO_WAIT);
} else if (timer->type == osTimerPeriodic) {
k_timer_start(&timer->z_timer, 0, millisec);
k_timer_start(&timer->z_timer, K_NO_WAIT, millisec);
}

timer->status = ACTIVE;
Expand Down
2 changes: 1 addition & 1 deletion lib/posix/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid)
return -1;
}

if (k_mem_slab_alloc(&posix_timer_slab, (void **)&timer, 100) == 0) {
if (k_mem_slab_alloc(&posix_timer_slab, (void **)&timer, K_MSEC(100)) == 0) {
(void)memset(timer, 0, sizeof(struct timer_obj));
} else {
errno = ENOMEM;
Expand Down
2 changes: 1 addition & 1 deletion samples/boards/nrf52/mesh/onoff-app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ static void button_pressed(struct device *dev, struct gpio_callback *cb,
}

if (button_press_cnt == 0U) {
k_timer_start(&sw.button_timer, K_SECONDS(1), 0);
k_timer_start(&sw.button_timer, K_SECONDS(1), K_NO_WAIT);
}

printk("button_press_cnt 0x%02x\n", button_press_cnt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ void main(void)
update_light_state();

short_time_multireset_bt_mesh_unprovisioning();
k_timer_start(&reset_counter_timer, K_MSEC(7000), 0);
k_timer_start(&reset_counter_timer, K_MSEC(7000), K_NO_WAIT);

#if defined(CONFIG_MCUMGR)
/* Initialize the Bluetooth mcumgr transport. */
smp_bt_register();

k_timer_start(&smp_svr_timer, 0, K_MSEC(1000));
k_timer_start(&smp_svr_timer, K_NO_WAIT, K_MSEC(1000));
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ static void no_transition_work_handler(struct k_work *work)
update_led_gpio();
}

k_timer_start(&unsolicitedly_publish_states_timer, K_MSEC(5000), 0);
k_timer_start(&unsolicitedly_publish_states_timer, K_MSEC(5000),
K_NO_WAIT);

/* If Lightness & Temperature values remains stable for
* 10 Seconds then & then only get stored on SoC flash.
*/
if (gen_power_onoff_srv_user_data.onpowerup == STATE_RESTORE) {
k_timer_start(&save_lightness_temp_last_values_timer,
K_MSEC(10000), 0);
K_MSEC(10000), K_NO_WAIT);
}
}

Expand Down
81 changes: 81 additions & 0 deletions scripts/coccinelle/int_literal_to_timeout.cocci
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) 2019 Nordic Semiconductor ASA
// SPDX-License-Identifer: Apache-2.0

// Replace integer constant timeouts with K_MSEC variants
//
// Some existing code assumes that timeout parameters are provided as
// integer milliseconds, when they were intended to be timeout values
// produced by specific constants and macros. Convert the integer
// literals to the desired equivalent.

// Handle k_timer_start delay parameters
@delay_id@
expression T, P;
position p;
identifier D;
@@
k_timer_start@p(T, D, P)

@@
expression T, P;
position p != delay_id.p;
@@
k_timer_start@p(T,
- 0
+ K_NO_WAIT
, P)

@@
expression T, P;
position p != delay_id.p;
@@
k_timer_start@p(T,
- -1
+ K_FOREVER
, P)

@@
expression T, P;
constant int D;
position p != delay_id.p;
@@
k_timer_start@p(T,
- D
+ K_MSEC(D)
, P)

// Handle timeouts at the end of the argument list
@end_id@
identifier f =~ "^k_(timer_start|queue_get|futex_wait|stack_pop|delayed_work_submit_to_queue|mutex_lock|sem_take|(msgq|mbox|pipe)_(block_)?(put|get)|mem_(slab|pool)_alloc|poll|thread_deadline_set)$";
position p;
identifier D;
@@
f@p(..., D)

@@
identifier f =~ "^k_(timer_start|queue_get|futex_wait|stack_pop|delayed_work_submit_to_queue|mutex_lock|sem_take|(msgq|mbox|pipe)_(block_)?(put|get)|mem_(slab|pool)_alloc|poll|thread_deadline_set)$";
position p != end_id.p;
@@
f@p(...,
- 0
+ K_NO_WAIT
)

@@
identifier f =~ "^k_(timer_start|queue_get|futex_wait|stack_pop|delayed_work_submit_to_queue|mutex_lock|sem_take|(msgq|mbox|pipe)_(block_)?(put|get)|mem_(slab|pool)_alloc|poll|thread_deadline_set)$";
position p != end_id.p;
@@
f@p(...,
- -1
+ K_FOREVER
)

@@
identifier f =~ "^k_(timer_start|queue_get|futex_wait|stack_pop|delayed_work_submit_to_queue|mutex_lock|sem_take|(msgq|mbox|pipe)_(block_)?(put|get)|mem_(slab|pool)_alloc|poll|thread_deadline_set)$";
position p != end_id.p;
constant int D;
@@
f@p(...,
- D
+ K_MSEC(D)
)
2 changes: 1 addition & 1 deletion subsys/logging/log_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static inline void msg_finalize(struct log_msg *msg,
irq_unlock(key);
} else if (proc_tid != NULL && buffered_cnt == 1) {
k_timer_start(&log_process_thread_timer,
CONFIG_LOG_PROCESS_THREAD_SLEEP_MS, 0);
CONFIG_LOG_PROCESS_THREAD_SLEEP_MS, K_NO_WAIT);
} else if (CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD) {
if ((buffered_cnt == CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD) &&
(proc_tid != NULL)) {
Expand Down
4 changes: 2 additions & 2 deletions subsys/net/l2/ethernet/gptp/gptp.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ void gptp_update_pdelay_req_interval(int port, s8_t log_val)
new_itv = 1;
}

k_timer_start(&state_pdelay->pdelay_timer, new_itv, 0);
k_timer_start(&state_pdelay->pdelay_timer, new_itv, K_NO_WAIT);
}

void gptp_update_sync_interval(int port, s8_t log_val)
Expand Down Expand Up @@ -814,7 +814,7 @@ void gptp_update_announce_interval(int port, s8_t log_val)
new_itv = 1;
}

k_timer_start(&state_ann->ann_send_periodic_timer, new_itv, 0);
k_timer_start(&state_ann->ann_send_periodic_timer, new_itv, K_NO_WAIT);
}

struct port_user_data {
Expand Down
4 changes: 2 additions & 2 deletions subsys/net/l2/ethernet/gptp/gptp_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static void gptp_md_pdelay_check_multiple_resp(int port)
duration = GPTP_MULTIPLE_PDELAY_RESP_WAIT -
gptp_uscaled_ns_to_timer_ms(&port_ds->pdelay_req_itv);

k_timer_start(&state->pdelay_timer, duration, 0);
k_timer_start(&state->pdelay_timer, duration, K_NO_WAIT);
} else {
state->state = GPTP_PDELAY_REQ_SEND_REQ;
}
Expand Down Expand Up @@ -636,7 +636,7 @@ static void gptp_md_pdelay_req_state_machine(int port)
k_timer_start(&state->pdelay_timer,
gptp_uscaled_ns_to_timer_ms(
&port_ds->pdelay_req_itv),
0);
K_NO_WAIT);
/*
* Transition directly to GPTP_PDELAY_REQ_WAIT_RESP.
* Check for the TX timestamp will be done during
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/l2/ethernet/gptp/gptp_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ void gptp_handle_sync(int port, struct net_pkt *pkt)
duration = (upstream_sync_itv / 1000000U);

/* Start timeout timer. */
k_timer_start(&state->follow_up_discard_timer, duration, 0);
k_timer_start(&state->follow_up_discard_timer, duration, K_NO_WAIT);
}

int gptp_handle_follow_up(int port, struct net_pkt *pkt)
Expand Down
Loading