Skip to content

Commit 040b143

Browse files
trond-snekviknashif
authored andcommitted
Bluetooth: 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. Signed-off-by: Trond Einar Snekvik <[email protected]>
1 parent 8f18b86 commit 040b143

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

subsys/bluetooth/mesh/friend.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,11 @@ static void enqueue_sub_cfm(struct bt_mesh_friend *frnd, uint8_t xact)
568568

569569
static void friend_recv_delay(struct bt_mesh_friend *frnd)
570570
{
571+
int32_t delay = recv_delay(frnd);
572+
571573
frnd->pending_req = 1U;
572-
k_delayed_work_submit(&frnd->timer, K_MSEC(recv_delay(frnd)));
573-
BT_DBG("Waiting RecvDelay of %d ms", recv_delay(frnd));
574+
k_delayed_work_submit(&frnd->timer, K_MSEC(delay));
575+
BT_DBG("Waiting RecvDelay of %d ms", delay);
574576
}
575577

576578
int bt_mesh_friend_sub_add(struct bt_mesh_net_rx *rx,
@@ -916,6 +918,7 @@ int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
916918
struct bt_mesh_ctl_friend_req *msg = (void *)buf->data;
917919
struct bt_mesh_friend *frnd = NULL;
918920
uint32_t poll_to;
921+
int32_t delay;
919922
int i, err;
920923

921924
if (rx->net_if == BT_MESH_NET_IF_LOCAL) {
@@ -1005,9 +1008,8 @@ int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
10051008
clear_procedure_start(frnd);
10061009
}
10071010

1008-
k_delayed_work_submit(&frnd->timer,
1009-
K_MSEC(offer_delay(frnd, rx->ctx.recv_rssi,
1010-
msg->criteria)));
1011+
delay = offer_delay(frnd, rx->ctx.recv_rssi, msg->criteria);
1012+
k_delayed_work_submit(&frnd->timer, K_MSEC(delay));
10111013

10121014
enqueue_offer(frnd, rx->ctx.recv_rssi);
10131015

subsys/bluetooth/mesh/lpn.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,9 @@ int bt_mesh_lpn_friend_sub_cfm(struct bt_mesh_net_rx *rx,
936936
}
937937

938938
if (!lpn->sent_req) {
939-
k_delayed_work_submit(&lpn->timer, K_MSEC(poll_timeout(lpn)));
939+
int32_t timeout = poll_timeout(lpn);
940+
941+
k_delayed_work_submit(&lpn->timer, K_MSEC(timeout));
940942
}
941943

942944
return 0;
@@ -1025,7 +1027,9 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx,
10251027
}
10261028

10271029
if (!lpn->sent_req) {
1028-
k_delayed_work_submit(&lpn->timer, K_MSEC(poll_timeout(lpn)));
1030+
int32_t timeout = poll_timeout(lpn);
1031+
1032+
k_delayed_work_submit(&lpn->timer, K_MSEC(timeout));
10291033
}
10301034

10311035
return 0;

subsys/bluetooth/mesh/transport.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ static void seg_rx_reset(struct seg_rx *rx, bool full_reset)
11101110
static void seg_ack(struct k_work *work)
11111111
{
11121112
struct seg_rx *rx = CONTAINER_OF(work, struct seg_rx, ack);
1113+
int32_t timeout;
11131114

11141115
BT_DBG("rx %p", rx);
11151116

@@ -1127,7 +1128,8 @@ static void seg_ack(struct k_work *work)
11271128
send_ack(rx->sub, rx->dst, rx->src, rx->ttl, &rx->seq_auth,
11281129
rx->block, rx->obo);
11291130

1130-
k_delayed_work_submit(&rx->ack, K_MSEC(ack_timeout(rx)));
1131+
timeout = ack_timeout(rx);
1132+
k_delayed_work_submit(&rx->ack, K_MSEC(timeout));
11311133
}
11321134

11331135
static inline bool sdu_len_is_ok(bool ctl, uint8_t seg_n)
@@ -1409,7 +1411,9 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx,
14091411

14101412
if (!k_delayed_work_remaining_get(&rx->ack) &&
14111413
!bt_mesh_lpn_established()) {
1412-
k_delayed_work_submit(&rx->ack, K_MSEC(ack_timeout(rx)));
1414+
int32_t timeout = ack_timeout(rx);
1415+
1416+
k_delayed_work_submit(&rx->ack, K_MSEC(timeout));
14131417
}
14141418

14151419
/* Allocated segment here */

0 commit comments

Comments
 (0)