From 0ef77d4ea41fb765061c64896b3fbd0b2e4bc276 Mon Sep 17 00:00:00 2001 From: Chih Hung Yu Date: Wed, 30 Jun 2021 14:40:16 +0800 Subject: [PATCH] kernel: Fix negative mutex lock_count value If you try to unlock an unlocked mutex, it will incorrectly succeeds and decreases the lock count to -1. Fixes #36572 Signed-off-by: Chih Hung Yu --- kernel/mutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/mutex.c b/kernel/mutex.c index c3c63c4f03618a..4e8b3d7f7b134f 100644 --- a/kernel/mutex.c +++ b/kernel/mutex.c @@ -230,7 +230,7 @@ int z_impl_k_mutex_unlock(struct k_mutex *mutex) * If we are the owner and count is greater than 1, then decrement * the count and return and keep current thread as the owner. */ - if (mutex->lock_count - 1U != 0U) { + if (mutex->lock_count > 1U) { mutex->lock_count--; goto k_mutex_unlock_return; }