Skip to content

Commit 973934c

Browse files
sjanccfriedt
authored andcommitted
Bluetooth: Host: Fix crash on bt_disable() with limited advertising
When limited advertising is enabled there is pending deleyable work for timing it out. If in such case struct bt_le_ext_adv is cleared by memset system will crash on next tick. Fix this by ensuring work is cancelled before clearing struct bt_le_ext_adv. Using bt_le_ext_adv_foreach() ensures that this will be correctly handled with and without extended advertising enabled. Signed-off-by: Szymon Janc <[email protected]>
1 parent 45a4f38 commit 973934c

File tree

1 file changed

+8
-4
lines changed
  • subsys/bluetooth/host

1 file changed

+8
-4
lines changed

subsys/bluetooth/host/adv.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "hci_core.h"
3535
#include "id.h"
3636
#include "scan.h"
37+
#include "adv.h"
3738

3839
#define LOG_LEVEL CONFIG_BT_HCI_CORE_LOG_LEVEL
3940
LOG_MODULE_REGISTER(bt_adv);
@@ -247,12 +248,15 @@ void bt_le_ext_adv_foreach(void (*func)(struct bt_le_ext_adv *adv, void *data),
247248
#endif /* defined(CONFIG_BT_EXT_ADV) */
248249
}
249250

250-
void bt_adv_reset_adv_pool(void)
251+
static void clear_ext_adv_instance(struct bt_le_ext_adv *adv, void *data)
251252
{
252-
#if defined(CONFIG_BT_EXT_ADV)
253-
(void)memset(&adv_pool, 0, sizeof(adv_pool));
254-
#endif /* defined(CONFIG_BT_EXT_ADV) */
253+
bt_le_lim_adv_cancel_timeout(adv);
254+
memset(adv, 0, sizeof(*adv));
255+
}
255256

257+
void bt_adv_reset_adv_pool(void)
258+
{
259+
bt_le_ext_adv_foreach(clear_ext_adv_instance, NULL);
256260
(void)memset(&bt_dev.adv, 0, sizeof(bt_dev.adv));
257261
}
258262

0 commit comments

Comments
 (0)