Skip to content

Commit

Permalink
[nrf fromtree] ipc: Drain pending work items before deregistering end…
Browse files Browse the repository at this point in the history
…point

The work item will attempt to dereference pointers that have been nulled
by the backend.

To avoid that, wait until all items currently on the queue have been
processed.

The symptom is a busfault on ARM, and is "fixed" by adding a
`k_msleep(1)` right before `ipc_service_deregister_endpoint()`. This
will in effect do the same thing as this patch, and allow the scheduler
to run the work item on the ipc workqueue.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
(cherry picked from commit f24a01e)
  • Loading branch information
jori-nordic authored and nordicjm committed Feb 19, 2024
1 parent 8cd3e47 commit 321387b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ static int deregister_ept(const struct device *instance, void *token)
{
struct backend_data_t *data = instance->data;
struct ipc_rpmsg_ept *rpmsg_ept;
static struct k_work_sync sync;

/* Instance is not ready */
if (atomic_get(&data->state) != STATE_INITED) {
Expand All @@ -469,6 +470,13 @@ static int deregister_ept(const struct device *instance, void *token)
return -ENOENT;
}

/* Drain pending work items before tearing down channel.
*
* Note: `k_work_flush` Faults on Cortex-M33 with "illegal use of EPSR"
* if `sync` is not declared static.
*/
k_work_flush(&data->mbox_work, &sync);

rpmsg_destroy_ept(&rpmsg_ept->ep);

memset(rpmsg_ept, 0, sizeof(struct ipc_rpmsg_ept));
Expand Down

0 comments on commit 321387b

Please sign in to comment.