Skip to content

Commit 570c8c2

Browse files
ajayparidagmarull
authored andcommitted
[nrf fromtree] net: l2: wifi: Protect processing of nm data
Use lock while accessing nm data. One of the use case is while setting regulatory, it accesses nm data, while from some other place also it can be accessed same time. Protected the nm data processing. Signed-off-by: Ajay Parida <[email protected]> (cherry picked from commit b930026)
1 parent f50ad41 commit 570c8c2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

subsys/net/l2/wifi/wifi_nm.c

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ LOG_MODULE_REGISTER(wifi_nm, CONFIG_WIFI_NM_LOG_LEVEL);
1010
#include <zephyr/kernel.h>
1111
#include <zephyr/net/wifi_nm.h>
1212

13+
/* Used to protect nm data */
14+
static K_MUTEX_DEFINE(wifi_nm_lock);
15+
1316
struct wifi_nm_instance *wifi_nm_get_instance(const char *name)
1417
{
1518
STRUCT_SECTION_FOREACH(wifi_nm_instance, nm) {
@@ -27,13 +30,16 @@ struct wifi_nm_instance *wifi_nm_get_instance_iface(struct net_if *iface)
2730
return false;
2831
}
2932

33+
k_mutex_lock(&wifi_nm_lock, K_FOREVER);
3034
STRUCT_SECTION_FOREACH(wifi_nm_instance, nm) {
3135
for (int i = 0; i < CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES; i++) {
3236
if (nm->mgd_ifaces[i] == iface) {
37+
k_mutex_unlock(&wifi_nm_lock);
3338
return nm;
3439
}
3540
}
3641
}
42+
k_mutex_unlock(&wifi_nm_lock);
3743

3844
return NULL;
3945
}
@@ -48,12 +54,15 @@ int wifi_nm_register_mgd_iface(struct wifi_nm_instance *nm, struct net_if *iface
4854
return -ENOTSUP;
4955
}
5056

57+
k_mutex_lock(&wifi_nm_lock, K_FOREVER);
5158
for (int i = 0; i < CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES; i++) {
5259
if (!nm->mgd_ifaces[i]) {
5360
nm->mgd_ifaces[i] = iface;
61+
k_mutex_unlock(&wifi_nm_lock);
5462
return 0;
5563
}
5664
}
65+
k_mutex_unlock(&wifi_nm_lock);
5766

5867
return -ENOMEM;
5968
}
@@ -64,12 +73,15 @@ int wifi_nm_unregister_mgd_iface(struct wifi_nm_instance *nm, struct net_if *ifa
6473
return -EINVAL;
6574
}
6675

76+
k_mutex_lock(&wifi_nm_lock, K_FOREVER);
6777
for (int i = 0; i < CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES; i++) {
6878
if (nm->mgd_ifaces[i] == iface) {
6979
nm->mgd_ifaces[i] = NULL;
80+
k_mutex_unlock(&wifi_nm_lock);
7081
return 0;
7182
}
7283
}
84+
k_mutex_unlock(&wifi_nm_lock);
7385

7486
return -ENOENT;
7587
}

0 commit comments

Comments
 (0)