Skip to content

Commit 1ea569d

Browse files
SeppoTakalommahadevan108
authored andcommitted
net: lib: coap_client: Protect initialization with mutex
Protect global list of clients with mutex. Signed-off-by: Seppo Takalo <[email protected]>
1 parent bb2f602 commit 1ea569d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

subsys/net/lib/coap/coap_client.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ LOG_MODULE_DECLARE(net_coap, CONFIG_COAP_LOG_LEVEL);
2020
#define BLOCK1_OPTION_SIZE 4
2121
#define PAYLOAD_MARKER_SIZE 1
2222

23+
static K_MUTEX_DEFINE(coap_client_mutex);
2324
static struct coap_client *clients[CONFIG_COAP_CLIENT_MAX_INSTANCES];
2425
static int num_clients;
2526
static K_SEM_DEFINE(coap_client_recv_sem, 0, 1);
@@ -1006,7 +1007,9 @@ int coap_client_init(struct coap_client *client, const char *info)
10061007
return -EINVAL;
10071008
}
10081009

1010+
k_mutex_lock(&coap_client_mutex, K_FOREVER);
10091011
if (num_clients >= CONFIG_COAP_CLIENT_MAX_INSTANCES) {
1012+
k_mutex_unlock(&coap_client_mutex);
10101013
return -ENOSPC;
10111014
}
10121015

@@ -1015,6 +1018,7 @@ int coap_client_init(struct coap_client *client, const char *info)
10151018
clients[num_clients] = client;
10161019
num_clients++;
10171020

1021+
k_mutex_unlock(&coap_client_mutex);
10181022
return 0;
10191023
}
10201024

0 commit comments

Comments
 (0)