From 5af8c6c1ff8d1004d11f3314e5311f50b89da86b Mon Sep 17 00:00:00 2001 From: Slawomir Blauciak Date: Fri, 23 Apr 2021 17:22:10 +0200 Subject: [PATCH] scheduler: guard against subdivision underflow on domain clear In some situations the domain clear routine might encounter a case, when the number of clients is decremented and 0, as such, a subsequent subdivision will result in an integer underflow. Signed-off-by: Slawomir Blauciak --- src/schedule/ll_schedule.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/schedule/ll_schedule.c b/src/schedule/ll_schedule.c index dad55c9e1730..1b0f73911f5e 100644 --- a/src/schedule/ll_schedule.c +++ b/src/schedule/ll_schedule.c @@ -331,9 +331,11 @@ static void schedule_ll_domain_clear(struct ll_schedule_data *sch, if (count == 1) { sch->domain->registered[cpu_get_id()] = false; - count = atomic_sub(&sch->domain->num_clients, 1); - if (count == 1) - domain_clear(sch->domain); + if (atomic_read(&sch->domain->num_clients)) { + count = atomic_sub(&sch->domain->num_clients, 1); + if (count == 1) + domain_clear(sch->domain); + } } tr_info(&ll_tr, "num_tasks %d total_num_tasks %d",