Skip to content

Commit

Permalink
kernel: Fix negative mutex lock_count value
Browse files Browse the repository at this point in the history
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 <chyu313@gmail.com>
  • Loading branch information
chyu313 authored and nashif committed Jul 6, 2021
1 parent 4c38ca1 commit 0ef77d4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion kernel/mutex.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0ef77d4

Please sign in to comment.