Skip to content

Commit 4d48909

Browse files
FlorianWeber1018nashif
authored andcommitted
rtio: workq: bugfix of memory allocation
This commit fixes the bug that the memory of the work request is freed up in the work handler, before it is not needed anymore by the p4wq. This is fixed now, by using the new done_handler in the p4wq for freeing up that memory. Signed-off-by: Florian Weber <[email protected]> (cherry picked from commit b55b9ae)
1 parent 2479683 commit 4d48909

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

subsys/rtio/rtio_workq.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,24 @@
1111
#define RTIO_WORKQ_PRIO_HIGH RTIO_WORKQ_PRIO_MED - 1
1212
#define RTIO_WORKQ_PRIO_LOW RTIO_WORKQ_PRIO_MED + 1
1313

14-
K_P4WQ_DEFINE(rtio_workq,
15-
CONFIG_RTIO_WORKQ_THREADS_POOL,
16-
CONFIG_RTIO_WORKQ_STACK_SIZE);
17-
1814
K_MEM_SLAB_DEFINE_STATIC(rtio_work_items_slab,
1915
sizeof(struct rtio_work_req),
2016
CONFIG_RTIO_WORKQ_POOL_ITEMS,
2117
4);
2218

19+
static void rtio_work_req_done_handler(struct k_p4wq_work *work)
20+
{
21+
struct rtio_work_req *req = CONTAINER_OF(work,
22+
struct rtio_work_req,
23+
work);
24+
k_mem_slab_free(&rtio_work_items_slab, req);
25+
}
26+
27+
K_P4WQ_DEFINE_WITH_DONE_HANDLER(rtio_workq,
28+
CONFIG_RTIO_WORKQ_THREADS_POOL,
29+
CONFIG_RTIO_WORKQ_STACK_SIZE,
30+
rtio_work_req_done_handler);
31+
2332
static void rtio_work_handler(struct k_p4wq_work *work)
2433
{
2534
struct rtio_work_req *req = CONTAINER_OF(work,
@@ -28,8 +37,6 @@ static void rtio_work_handler(struct k_p4wq_work *work)
2837
struct rtio_iodev_sqe *iodev_sqe = req->iodev_sqe;
2938

3039
req->handler(iodev_sqe);
31-
32-
k_mem_slab_free(&rtio_work_items_slab, req);
3340
}
3441

3542
struct rtio_work_req *rtio_work_req_alloc(void)

0 commit comments

Comments
 (0)