git: 3beb43dd4f87 - main - callout: assert that callout_init_*lock* functions are called with a lock

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Thu, 20 Jun 2024 17:53:52 UTC
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=3beb43dd4f87fee0a8f5536ad103664374f9b97b

commit 3beb43dd4f87fee0a8f5536ad103664374f9b97b
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2024-06-20 17:53:31 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2024-06-20 17:53:31 +0000

    callout: assert that callout_init_*lock* functions are called with a lock
    
    Quick grep around kernel confirms they all do.
---
 sys/kern/kern_timeout.c | 5 ++---
 sys/sys/callout.h       | 9 +++------
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c
index e06cf997ab8a..699a57d51f0e 100644
--- a/sys/kern/kern_timeout.c
+++ b/sys/kern/kern_timeout.c
@@ -1331,11 +1331,10 @@ callout_init(struct callout *c, int mpsafe)
 void
 _callout_init_lock(struct callout *c, struct lock_object *lock, int flags)
 {
+	KASSERT(lock != NULL, ("%s: no lock", __func__));
 	KASSERT((flags & ~(CALLOUT_RETURNUNLOCKED | CALLOUT_SHAREDLOCK)) == 0,
 	    ("%s: bad flags %d", __func__, flags));
-	KASSERT(lock != NULL || (flags & CALLOUT_RETURNUNLOCKED) == 0,
-	    ("%s: CALLOUT_RETURNUNLOCKED with no lock", __func__));
-	KASSERT(lock == NULL || !(LOCK_CLASS(lock)->lc_flags & LC_SLEEPABLE),
+	KASSERT(!(LOCK_CLASS(lock)->lc_flags & LC_SLEEPABLE),
 	    ("%s: callout %p has sleepable lock", __func__, c));
 
 	*c = (struct callout ){
diff --git a/sys/sys/callout.h b/sys/sys/callout.h
index f2a5bf92ab46..5d0d896b5d3b 100644
--- a/sys/sys/callout.h
+++ b/sys/sys/callout.h
@@ -85,14 +85,11 @@
 void	callout_init(struct callout *, int);
 void	_callout_init_lock(struct callout *, struct lock_object *, int);
 #define	callout_init_mtx(c, mtx, flags)					\
-	_callout_init_lock((c), ((mtx) != NULL) ? &(mtx)->lock_object :	\
-	    NULL, (flags))
+	_callout_init_lock((c), &(mtx)->lock_object, (flags))
 #define	callout_init_rm(c, rm, flags)					\
-	_callout_init_lock((c), ((rm) != NULL) ? &(rm)->lock_object : 	\
-	    NULL, (flags))
+	_callout_init_lock((c), &(rm)->lock_object, (flags))
 #define	callout_init_rw(c, rw, flags)					\
-	_callout_init_lock((c), ((rw) != NULL) ? &(rw)->lock_object :	\
-	   NULL, (flags))
+	_callout_init_lock((c), &(rw)->lock_object, (flags))
 #define	callout_pending(c)	((c)->c_iflags & CALLOUT_PENDING)
 int	callout_reset_sbt_on(struct callout *, sbintime_t, sbintime_t,
 	    void (*)(void *), void *, int, int);