mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-07 12:25:00 -04:00
net: qrtr: Use cyclic idr allocator for port assignment
Use cyclic id allocator to avoid immediate reassignment of same port id. Assigning incremental port id gives more clarity over ports assignment and makes it easy to debug problem in certain scenario. Change-Id: Ib432ff641f4c81ba33ff0176cb67f1cdf4b3b1f9 Signed-off-by: Deepak Kumar Singh <deesin@codeaurora.org>
This commit is contained in:
parent
a9eb6ca4c9
commit
822ff8ce4c
1 changed files with 12 additions and 14 deletions
|
|
@ -1381,27 +1381,25 @@ static void qrtr_port_remove(struct qrtr_sock *ipc)
|
|||
*/
|
||||
static int qrtr_port_assign(struct qrtr_sock *ipc, int *port)
|
||||
{
|
||||
u32 min_port;
|
||||
int rc;
|
||||
|
||||
if (!*port) {
|
||||
min_port = QRTR_MIN_EPH_SOCKET;
|
||||
rc = idr_alloc_u32(&qrtr_ports, ipc, &min_port, QRTR_MAX_EPH_SOCKET, GFP_ATOMIC);
|
||||
if (!rc)
|
||||
*port = min_port;
|
||||
rc = idr_alloc_cyclic(&qrtr_ports, ipc, QRTR_MIN_EPH_SOCKET,
|
||||
QRTR_MAX_EPH_SOCKET + 1, GFP_ATOMIC);
|
||||
if (rc >= 0)
|
||||
*port = rc;
|
||||
} else if (*port < QRTR_MIN_EPH_SOCKET &&
|
||||
!(capable(CAP_NET_ADMIN) ||
|
||||
in_egroup_p(AID_VENDOR_QRTR) ||
|
||||
in_egroup_p(GLOBAL_ROOT_GID))) {
|
||||
!(capable(CAP_NET_ADMIN) ||
|
||||
in_egroup_p(AID_VENDOR_QRTR) ||
|
||||
in_egroup_p(GLOBAL_ROOT_GID))) {
|
||||
rc = -EACCES;
|
||||
} else if (*port == QRTR_PORT_CTRL) {
|
||||
min_port = 0;
|
||||
rc = idr_alloc_u32(&qrtr_ports, ipc, &min_port, 0, GFP_ATOMIC);
|
||||
rc = idr_alloc(&qrtr_ports, ipc, 0, 1, GFP_ATOMIC);
|
||||
} else {
|
||||
min_port = *port;
|
||||
rc = idr_alloc_u32(&qrtr_ports, ipc, &min_port, *port, GFP_ATOMIC);
|
||||
if (!rc)
|
||||
*port = min_port;
|
||||
rc = idr_alloc_cyclic(&qrtr_ports, ipc, *port, *port + 1,
|
||||
GFP_ATOMIC);
|
||||
if (rc >= 0)
|
||||
*port = rc;
|
||||
}
|
||||
|
||||
if (rc == -ENOSPC)
|
||||
|
|
|
|||
Loading…
Reference in a new issue