system/bt
Revision | 98eeab03cf9eb7530f617684e5f32ceb25934855 (tree) |
---|---|
Time | 2020-02-12 10:19:17 |
Author | Jack He <siyuanh@goog...> |
Commiter | android-build-team Robot |
L2CAP Socket: Keep track of last allocated socket ID
* Keep track of last allocated socket ID in L2CAP socket stack
* Use last_sock_id + 1 as new IDs when allocating new socket blocks
* The de-dupe and overflow detection mechanism in btsock_l2cap_alloc_l()
Test: CtsBluetoothTestCases
Bug: 144148429
Change-Id: Ieb9791ffa34eef919a32e4aff6f4b514859c69c0
(cherry picked from commit 79eda3270bbd23814b5ec73ee3fd96ac80222db8)
(cherry picked from commit eb4e9162b91995ae8318745c42dad32e972a8bbd)
@@ -97,6 +97,7 @@ static void btsock_l2cap_server_listen(l2cap_socket* sock); | ||
97 | 97 | static std::mutex state_lock; |
98 | 98 | |
99 | 99 | l2cap_socket* socks = NULL; |
100 | +static uint32_t last_sock_id = 0; | |
100 | 101 | static uid_set_t* uid_set = NULL; |
101 | 102 | static int pth = -1; |
102 | 103 |
@@ -327,7 +328,7 @@ static l2cap_socket* btsock_l2cap_alloc_l(const char* name, | ||
327 | 328 | sock->next = socks; |
328 | 329 | sock->prev = NULL; |
329 | 330 | if (socks) socks->prev = sock; |
330 | - sock->id = (socks ? socks->id : 0) + 1; | |
331 | + sock->id = last_sock_id + 1; | |
331 | 332 | sock->tx_bytes = 0; |
332 | 333 | sock->rx_bytes = 0; |
333 | 334 | socks = sock; |
@@ -345,6 +346,7 @@ static l2cap_socket* btsock_l2cap_alloc_l(const char* name, | ||
345 | 346 | if (!++sock->id) /* no zero IDs allowed */ |
346 | 347 | sock->id++; |
347 | 348 | } |
349 | + last_sock_id = sock->id; | |
348 | 350 | DVLOG(2) << __func__ << " SOCK_LIST: alloc id:" << sock->id; |
349 | 351 | return sock; |
350 | 352 |