Bluetooth: Mesh: Fix postponing storage deadline indefinitely

If the local node keeps getting bombarded with messages, it's possible
that the storage timer gets rescheduled over and over again and never
expires. Add the necessary code to only reschedule the timer if the
new deadline is earlier than an existing one.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2019-05-07 18:32:27 +03:00 committed by Johan Hedberg
commit e9ed634654

View file

@ -821,7 +821,7 @@ BT_SETTINGS_DEFINE(mesh, mesh_set, mesh_commit, NULL);
static void schedule_store(int flag)
{
s32_t timeout;
s32_t timeout, remaining;
atomic_set_bit(bt_mesh.flags, flag);
@ -836,6 +836,12 @@ static void schedule_store(int flag)
timeout = K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT);
}
remaining = k_delayed_work_remaining_get(&pending_store);
if (remaining && remaining < timeout) {
BT_DBG("Not rescheduling due to existing earlier deadline");
return;
}
BT_DBG("Waiting %d seconds", timeout / MSEC_PER_SEC);
k_delayed_work_submit(&pending_store, timeout);