Skip to content
Permalink
Browse files

wifi: eswifi: Allow nested locking

In order to prevent potential deadlock in various callbacks such as
accept, recv, etc... Add support for nested eswifi locking, allowing
callee to safely access back to the eswifi methods.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
  • Loading branch information...
Loic Poulain authored and jukkar committed Feb 13, 2019
1 parent 50fa6bd commit 033b26708501814be4bffb0a6be1cfd3a940a5a0
Showing with 15 additions and 2 deletions.
  1. +15 −2 drivers/wifi/eswifi/eswifi.h
@@ -9,6 +9,7 @@

#include <zephyr.h>
#include <kernel.h>
#include <kernel_structs.h>

#include <net/wifi_mgmt.h>

@@ -71,6 +72,8 @@ struct eswifi_dev {
u8_t mac[6];
char buf[MAX_DATA_SIZE];
struct k_mutex mutex;
atomic_val_t mutex_owner;
unsigned int mutex_depth;
void *bus_data;
struct eswifi_off_socket socket[ESWIFI_OFFLOAD_MAX_SOCKETS];
};
@@ -89,12 +92,22 @@ static inline int eswifi_request(struct eswifi_dev *eswifi, char *cmd,

static inline void eswifi_lock(struct eswifi_dev *eswifi)
{
k_mutex_lock(&eswifi->mutex, K_FOREVER);
/* Nested locking */
if (atomic_get(&eswifi->mutex_owner) != (atomic_t)(uintptr_t)_current) {
k_mutex_lock(&eswifi->mutex, K_FOREVER);
atomic_set(&eswifi->mutex_owner, (atomic_t)(uintptr_t)_current);
eswifi->mutex_depth = 1;
} else {
eswifi->mutex_depth++;
}
}

static inline void eswifi_unlock(struct eswifi_dev *eswifi)
{
k_mutex_unlock(&eswifi->mutex);
if (!--eswifi->mutex_depth) {
atomic_set(&eswifi->mutex_owner, -1);
k_mutex_unlock(&eswifi->mutex);
}
}

extern struct eswifi_bus_ops eswifi_bus_ops_spi;

0 comments on commit 033b267

Please sign in to comment.
You can’t perform that action at this time.