Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion subsys/bluetooth/host/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1501,8 +1501,11 @@ void bt_conn_unref(struct bt_conn *conn)

old = atomic_dec(&conn->ref);
/* Prevent from accessing connection object */
conn = NULL;
deallocated = (atomic_get(&old) == 1);
IF_ENABLED(CONFIG_BT_CONN_TX,
(__ASSERT(!(deallocated && k_work_is_pending(&conn->tx_complete_work)),
"tx_complete_work is pending when conn is deallocated")));
conn = NULL;
Copy link
Preview

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting conn to NULL after the assertion will cause the assertion to access a NULL pointer. The conn = NULL assignment should remain after the assertion, but the assertion should be moved before this line or use a different approach to access the work structure.

Copilot uses AI. Check for mistakes.


LOG_DBG("handle %u ref %ld -> %ld", conn_handle, old, (old - 1));

Expand Down
9 changes: 9 additions & 0 deletions subsys/bluetooth/host/iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,15 @@ static void bt_iso_chan_disconnected(struct bt_iso_chan *chan, uint8_t reason)
}
#endif /* CONFIG_BT_ISO_CENTRAL */
}
} else if (IS_ENABLED(CONFIG_BT_ISO_BROADCASTER) &&
conn_type == BT_ISO_CHAN_TYPE_BROADCASTER) {
/* BIS do not get a HCI Disconnected event and will not handle cleanup of pending TX
* complete in the same way as ACL and CIS do. Call bt_conn_tx_notify directly here
* to flush the chan->iso->tx_complete for each disconnected BIS
*/
bt_conn_tx_notify(chan->iso, true);
} else {
/* No special handling for BT_ISO_CHAN_TYPE_SYNC_RECEIVER */
}
}

Expand Down
6 changes: 5 additions & 1 deletion tests/bluetooth/host/conn/mocks/kernel.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
* Copyright (c) 2024-2025 Nordic Semiconductor ASA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC we don't need to update copyright year.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't we ever managed to write and guidelines on this :D I usually just update them when I remember them, but I can omit it if you prefer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me. I remember getting such comment long time ago, but can't find it now.

*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdbool.h>

#include <zephyr/fff.h>
#include <zephyr/kernel.h>

#include "kernel.h"
Expand All @@ -22,6 +25,7 @@ DEFINE_FAKE_VALUE_FUNC(int, k_work_submit, struct k_work *);
DEFINE_FAKE_VALUE_FUNC(int, k_work_submit_to_queue, struct k_work_q *, struct k_work *);
DEFINE_FAKE_VALUE_FUNC(int, k_work_reschedule, struct k_work_delayable *, k_timeout_t);
DEFINE_FAKE_VALUE_FUNC(int, k_work_schedule, struct k_work_delayable *, k_timeout_t);
DEFINE_FAKE_VALUE_FUNC(int, k_work_busy_get, const struct k_work *);
DEFINE_FAKE_VOID_FUNC(k_queue_init, struct k_queue *);
DEFINE_FAKE_VOID_FUNC(k_queue_append, struct k_queue *, void *);
DEFINE_FAKE_VALUE_FUNC(int, k_queue_is_empty, struct k_queue *);
Expand Down
4 changes: 3 additions & 1 deletion tests/bluetooth/host/conn/mocks/kernel.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
* Copyright (c) 2024-2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdbool.h>

#include <zephyr/kernel.h>
#include <zephyr/fff.h>
Expand Down Expand Up @@ -42,6 +43,7 @@ DECLARE_FAKE_VOID_FUNC(k_sem_give, struct k_sem *);
DECLARE_FAKE_VALUE_FUNC(k_tid_t, k_sched_current_thread_query);
DECLARE_FAKE_VOID_FUNC(k_work_init, struct k_work *, k_work_handler_t);
DECLARE_FAKE_VOID_FUNC(k_work_init_delayable, struct k_work_delayable *, k_work_handler_t);
DECLARE_FAKE_VALUE_FUNC(int, k_work_busy_get, const struct k_work *);
DECLARE_FAKE_VALUE_FUNC(int, k_work_cancel_delayable, struct k_work_delayable *);
DECLARE_FAKE_VALUE_FUNC(bool, k_work_flush, struct k_work *, struct k_work_sync *);
DECLARE_FAKE_VALUE_FUNC(int, k_work_submit, struct k_work *);
Expand Down