mesh: Pull all function calls out of the K_MSEC macro
The K_MSEC macro evaluates its argument twice, which causes double
evaluation of some function calls in the mesh stack.
This removes all instances of function calls inside K_MSEC macros in the
mesh stack.
This is port of 040b14366ebbf58d49fc21d02dc6ec9aa51e90d9
diff --git a/nimble/host/mesh/src/friend.c b/nimble/host/mesh/src/friend.c
index 41a1702..3d7d4b2 100644
--- a/nimble/host/mesh/src/friend.c
+++ b/nimble/host/mesh/src/friend.c
@@ -585,9 +585,11 @@
static void friend_recv_delay(struct bt_mesh_friend *frnd)
{
+ int32_t delay = recv_delay(frnd);
+
frnd->pending_req = 1;
- k_delayed_work_submit(&frnd->timer, recv_delay(frnd));
- BT_DBG("Waiting RecvDelay of %d ms", (int) recv_delay(frnd));
+ k_delayed_work_submit(&frnd->timer, K_MSEC(delay));
+ BT_DBG("Waiting RecvDelay of %d ms", delay);
}
int bt_mesh_friend_sub_add(struct bt_mesh_net_rx *rx,
@@ -932,6 +934,7 @@
struct bt_mesh_ctl_friend_req *msg = (void *)buf->om_data;
struct bt_mesh_friend *frnd = NULL;
uint32_t poll_to;
+ int32_t delay;
int i, err;
if (rx->net_if == BT_MESH_NET_IF_LOCAL) {
@@ -1022,9 +1025,8 @@
clear_procedure_start(frnd);
}
- k_delayed_work_submit(&frnd->timer,
- offer_delay(frnd, rx->ctx.recv_rssi,
- msg->criteria));
+ delay = offer_delay(frnd, rx->ctx.recv_rssi, msg->criteria);
+ k_delayed_work_submit(&frnd->timer, K_MSEC(delay));
enqueue_offer(frnd, rx->ctx.recv_rssi);
diff --git a/nimble/host/mesh/src/lpn.c b/nimble/host/mesh/src/lpn.c
index e9e4125..f2045c8 100644
--- a/nimble/host/mesh/src/lpn.c
+++ b/nimble/host/mesh/src/lpn.c
@@ -923,7 +923,9 @@
}
if (!lpn->sent_req) {
- k_delayed_work_submit(&lpn->timer, poll_timeout(lpn));
+ int32_t timeout = poll_timeout(lpn);
+
+ k_delayed_work_submit(&lpn->timer, K_MSEC(timeout));
}
return 0;
@@ -1009,7 +1011,9 @@
}
if (!lpn->sent_req) {
- k_delayed_work_submit(&lpn->timer, poll_timeout(lpn));
+ int32_t timeout = poll_timeout(lpn);
+
+ k_delayed_work_submit(&lpn->timer, K_MSEC(timeout));
}
return 0;
diff --git a/nimble/host/mesh/src/transport.c b/nimble/host/mesh/src/transport.c
index 4cc1b08..5a91972 100644
--- a/nimble/host/mesh/src/transport.c
+++ b/nimble/host/mesh/src/transport.c
@@ -1109,6 +1109,7 @@
static void seg_ack(struct ble_npl_event *work)
{
struct seg_rx *rx = ble_npl_event_get_arg(work);
+ int32_t timeout;
BT_DBG("rx %p", rx);
@@ -1126,7 +1127,8 @@
send_ack(rx->sub, rx->dst, rx->src, rx->ttl, &rx->seq_auth,
rx->block, rx->obo);
- k_delayed_work_submit(&rx->ack, ack_timeout(rx));
+ timeout = ack_timeout(rx);
+ k_delayed_work_submit(&rx->ack, K_MSEC(timeout));
}
static inline bool sdu_len_is_ok(bool ctl, uint8_t seg_n)
@@ -1409,7 +1411,9 @@
if (!k_delayed_work_remaining_get(&rx->ack) &&
!bt_mesh_lpn_established()) {
- k_delayed_work_submit(&rx->ack, ack_timeout(rx));
+ int32_t timeout = ack_timeout(rx);
+
+ k_delayed_work_submit(&rx->ack, K_MSEC(timeout));
}
/* Allocated segment here */