From b9d70365a1cd722018ca4feb3f26b1fa20294465 Mon Sep 17 00:00:00 2001 From: chao an Date: Sat, 28 Jan 2023 13:24:04 +0800 Subject: [PATCH] sched/wqueue: semaphore count should be consistent with the number of work entries. The number of work entries will be inconsistent with semaphore count if the work is canceled, in extreme case, semaphore count will overflow and fallback to 0 the workqueue will stop scheduling the enqueue work. Signed-off-by: chao an --- sched/wqueue/kwork_cancel.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sched/wqueue/kwork_cancel.c b/sched/wqueue/kwork_cancel.c index 340d861ce5..fd8055ea04 100644 --- a/sched/wqueue/kwork_cancel.c +++ b/sched/wqueue/kwork_cancel.c @@ -88,6 +88,12 @@ static int work_qcancel(FAR struct kwork_wqueue_s *wqueue, else { dq_rem((FAR dq_entry_t *)work, &wqueue->q); + + /* Semaphore count should be consistent with the number of + * work entries. + */ + + wqueue->sem.semcount--; } work->worker = NULL;