Bluetooth: Fix giving back pkts semaphore when disconnecting

The TX fiber might be blocked waiting for the num_pkts semaphore when
a disconnection occurs. If we only give back the semaphore once
exiting the while-loop we may end up in a deadlock. Giving back the
semaphore in the connection disconnect handler solves this.

An additional fix this patch does is to ensure that we don't perform
integer underflow because of the last iteration.

Change-Id: Ia67dc506885d0c2bad25c598ea349f1fd251218b
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2016-09-13 08:52:28 +03:00
commit 37d204e03d

View file

@ -1004,12 +1004,7 @@ static void conn_tx_fiber(int arg1, int arg2)
net_buf_unref(buf);
}
/* Return any unacknowledged packets */
if (conn->pending_pkts) {
while (conn->pending_pkts--) {
nano_fiber_sem_give(bt_conn_get_pkts(conn));
}
}
BT_ASSERT(!conn->pending_pkts);
bt_conn_reset_rx_state(conn);
@ -1115,6 +1110,12 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
notify_connected(conn);
}
/* Return any unacknowledged packets */
while (conn->pending_pkts) {
nano_fiber_sem_give(bt_conn_get_pkts(conn));
conn->pending_pkts--;
}
/* Cancel Connection Update if it is pending */
if (conn->type == BT_CONN_TYPE_LE)
nano_delayed_work_cancel(&conn->le.update_work);