From 935509a42a86737b8dec4bd17f377497e52e7d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Tue, 15 Dec 2020 11:24:00 +0100 Subject: [PATCH] mesh: avoid improper access to internal structures Nothing in the API description the delayed work structure sanctions direct reference to internal fields. Do not assume that a delayed work item can be submitted without delay by invoking k_work_submit() with a reference to the contained work item. Instead submit with the delayed API and no wait. This is port of cd2a5dd6124940f1be5345cc4dae800808a08d1f --- nimble/host/mesh/src/beacon.c | 6 +++--- nimble/host/mesh/src/heartbeat.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nimble/host/mesh/src/beacon.c b/nimble/host/mesh/src/beacon.c index a79e52063..6a5fc5a1c 100644 --- a/nimble/host/mesh/src/beacon.c +++ b/nimble/host/mesh/src/beacon.c @@ -438,7 +438,7 @@ void bt_mesh_beacon_ivu_initiator(bool enable) atomic_set_bit_to(bt_mesh.flags, BT_MESH_IVU_INITIATOR, enable); if (enable) { - k_work_submit(&beacon_timer.work); + k_delayed_work_submit(&beacon_timer, K_NO_WAIT); } else if (!bt_mesh_beacon_enabled()) { k_delayed_work_cancel(&beacon_timer); } @@ -455,13 +455,13 @@ static void subnet_beacon_enable(struct bt_mesh_subnet *sub) void bt_mesh_beacon_enable(void) { if (!bt_mesh_is_provisioned()) { - k_work_submit(&beacon_timer.work); + k_delayed_work_submit(&beacon_timer, K_NO_WAIT); return; } bt_mesh_subnet_foreach(subnet_beacon_enable); - k_work_submit(&beacon_timer.work); + k_delayed_work_submit(&beacon_timer, K_NO_WAIT); } void bt_mesh_beacon_disable(void) diff --git a/nimble/host/mesh/src/heartbeat.c b/nimble/host/mesh/src/heartbeat.c index e1508d4bf..538a1cb66 100644 --- a/nimble/host/mesh/src/heartbeat.c +++ b/nimble/host/mesh/src/heartbeat.c @@ -236,7 +236,7 @@ uint8_t bt_mesh_hb_pub_set(struct bt_mesh_hb_pub *new_pub) * periodic publishing. */ if (pub.period && pub.count) { - k_work_submit(&pub_timer.work); + k_delayed_work_submit(&pub_timer, K_NO_WAIT); } else { k_delayed_work_cancel(&pub_timer); } @@ -333,7 +333,7 @@ void bt_mesh_hb_start(void) { if (pub.count && pub.period) { BT_DBG("Starting heartbeat publication"); - k_work_submit(&pub_timer.work); + k_delayed_work_submit(&pub_timer, K_NO_WAIT); } } @@ -346,6 +346,6 @@ void bt_mesh_hb_resume(void) { if (pub.period && pub.count) { BT_DBG("Starting heartbeat publication"); - k_work_submit(&pub_timer.work); + k_delayed_work_submit(&pub_timer, K_NO_WAIT); } }