From 3fc5150f36f2923069f73b55a0bb55eb9b70e8c3 Mon Sep 17 00:00:00 2001 From: Carlo Caione Date: Wed, 16 Mar 2022 10:47:58 +0100 Subject: [PATCH] ipc_service: static_vrings: Use atomic helpers Use the correct atomic helpers when accessing atomic_t variables and fix a possible race condition. Signed-off-by: Carlo Caione --- .../backends/ipc_rpmsg_static_vrings.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c b/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c index be77774a8eb..5a342f275ba 100644 --- a/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c +++ b/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c @@ -352,16 +352,11 @@ static int register_ept(const struct device *instance, void **token, struct ipc_rpmsg_instance *rpmsg_inst; struct ipc_rpmsg_ept *rpmsg_ept; - /* Instance is still being initialized */ - if (data->state == STATE_BUSY) { + /* Instance is not ready */ + if (atomic_get(&data->state) != STATE_INITED) { return -EBUSY; } - /* Instance is not initialized */ - if (data->state == STATE_READY) { - return -EINVAL; - } - /* Empty name is not valid */ if (cfg->name == NULL || cfg->name[0] == '\0') { return -EINVAL; @@ -387,16 +382,11 @@ static int send(const struct device *instance, void *token, struct backend_data_t *data = instance->data; struct ipc_rpmsg_ept *rpmsg_ept; - /* Instance is still being initialized */ - if (data->state == STATE_BUSY) { + /* Instance is not ready */ + if (atomic_get(&data->state) != STATE_INITED) { return -EBUSY; } - /* Instance is not initialized */ - if (data->state == STATE_READY) { - return -EINVAL; - } - /* Empty message is not allowed */ if (len == 0) { return -EBADMSG;