Skip to content

Commit

Permalink
Bluetooth: Mesh: Fix Assert in bt_mesh_adv_unref when messages to a p…
Browse files Browse the repository at this point in the history
…roxy

Fixes:#83904

This solution fix is to define a separate variable for the each proxy FIFO.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
(cherry picked from commit 6371080)
  • Loading branch information
LingaoM authored and dkalowsk committed Feb 13, 2025
1 parent da7ec06 commit f001cf6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
6 changes: 5 additions & 1 deletion subsys/bluetooth/mesh/adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ struct bt_mesh_adv_ctx {
};

struct bt_mesh_adv {
sys_snode_t node;
void *adv_bearer;

#if defined(CONFIG_BT_MESH_GATT)
void *gatt_bearer[CONFIG_BT_MAX_CONN];
#endif

struct bt_mesh_adv_ctx ctx;

Expand Down
24 changes: 21 additions & 3 deletions subsys/bluetooth/mesh/proxy_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ static struct bt_mesh_proxy_role roles[CONFIG_BT_MAX_CONN];

static int conn_count;

static void proxy_queue_put(struct bt_mesh_proxy_role *role, struct bt_mesh_adv *adv)
{
k_fifo_put(&role->pending, &(adv->gatt_bearer[bt_conn_index(role->conn)]));
}

static struct bt_mesh_adv *proxy_queue_get(struct bt_mesh_proxy_role *role)
{
void *gatt_bearer;

gatt_bearer = k_fifo_get(&role->pending, K_NO_WAIT);
if (!gatt_bearer) {
return NULL;
}

return CONTAINER_OF(gatt_bearer, struct bt_mesh_adv,
gatt_bearer[bt_conn_index(role->conn)]);
}

static void proxy_sar_timeout(struct k_work *work)
{
struct bt_mesh_proxy_role *role;
Expand All @@ -66,7 +84,7 @@ static void proxy_sar_timeout(struct k_work *work)
role = CONTAINER_OF(dwork, struct bt_mesh_proxy_role, sar_timer);

while (!k_fifo_is_empty(&role->pending)) {
struct bt_mesh_adv *adv = k_fifo_get(&role->pending, K_NO_WAIT);
struct bt_mesh_adv *adv = proxy_queue_get(role);

__ASSERT_NO_MSG(adv);

Expand Down Expand Up @@ -243,7 +261,7 @@ int bt_mesh_proxy_relay_send(struct bt_conn *conn, struct bt_mesh_adv *adv)
{
struct bt_mesh_proxy_role *role = &roles[bt_conn_index(conn)];

k_fifo_put(&role->pending, bt_mesh_adv_ref(adv));
proxy_queue_put(role, bt_mesh_adv_ref(adv));

bt_mesh_wq_submit(&role->work);

Expand All @@ -259,7 +277,7 @@ static void proxy_msg_send_pending(struct k_work *work)
return;
}

adv = k_fifo_get(&role->pending, K_NO_WAIT);
adv = proxy_queue_get(role);
if (!adv) {
return;
}
Expand Down

0 comments on commit f001cf6

Please sign in to comment.