From c6eec813b04039d1496308dd11218b7a4895d3b5 Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Mon, 9 Sep 2024 19:50:20 -0400 Subject: [PATCH] Assert unlock doesn't underflow lock user count. While debugging a double unlock error we hit this condition and debugging would have been a lot easier had we enforced this simple constraint that we can't decrement the lock users count if it's already 0. Signed-off-by: Auke Kok --- kmod/src/lock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kmod/src/lock.c b/kmod/src/lock.c index 5f280054..ce77bb51 100644 --- a/kmod/src/lock.c +++ b/kmod/src/lock.c @@ -302,6 +302,7 @@ static void lock_inc_count(unsigned int *counts, enum scoutfs_lock_mode mode) static void lock_dec_count(unsigned int *counts, enum scoutfs_lock_mode mode) { BUG_ON(mode < 0 || mode >= SCOUTFS_LOCK_NR_MODES); + BUG_ON(counts[mode] == 0); counts[mode]--; }