Commit 52f9c0dd authored by Joakim Andersson's avatar Joakim Andersson Committed by Carles Cufi
Browse files

Bluetooth: host: Fix resume advertiser race condition

This patch fixes an issue with the advertiser not resuming connectable
advertiser if the last bt_conn_unref happens from something other
than the disconnected callback.
In this case this last bt_conn_unref was from gatt.c notify_cb called
from application main thread.

Signed-off-by: default avatarJoakim Andersson <joakim.andersson@nordicsemi.no>
parent 4be66bd3
Loading
Loading
Loading
Loading
+5 −8
Changes for subsys/bluetooth/host/conn.c: 5 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -364,14 +364,6 @@ static void conn_update_timeout(struct k_work *work)
		 * state transition.
		 */
		bt_conn_unref(conn);

		/* A new reference likely to have been released here,
		 * Resume advertising.
		 */
		if (IS_ENABLED(CONFIG_BT_PERIPHERAL)) {
			bt_le_adv_resume();
		}

		return;
	}

@@ -1977,6 +1969,11 @@ void bt_conn_unref(struct bt_conn *conn)

	BT_DBG("handle %u ref %u -> %u", conn->handle, old,
	       atomic_get(&conn->ref));

	if (IS_ENABLED(CONFIG_BT_PERIPHERAL) &&
	    atomic_get(&conn->ref) == 0) {
		bt_le_adv_resume();
	}
}

const bt_addr_le_t *bt_conn_get_dst(const struct bt_conn *conn)
+1 −6
Changes for subsys/bluetooth/host/hci_core.c: 1 added line, 6 removed lines.
Original line number Diff line number Diff line
@@ -1672,7 +1672,7 @@ static void hci_disconn_complete(struct net_buf *buf)
	conn = bt_conn_lookup_handle(handle);
	if (!conn) {
		BT_ERR("Unable to look up conn with handle %u", handle);
		goto advertise;
		return;
	}

	conn->err = evt->reason;
@@ -1707,11 +1707,6 @@ static void hci_disconn_complete(struct net_buf *buf)
#endif /* defined(CONFIG_BT_CENTRAL) && !defined(CONFIG_BT_WHITELIST) */

	bt_conn_unref(conn);

advertise:
	if (IS_ENABLED(CONFIG_BT_PERIPHERAL)) {
		bt_le_adv_resume();
	}
}

static int hci_le_read_remote_features(struct bt_conn *conn)