callout: assert that callout_init_*lock* functions are called with a lock

Quick grep around kernel confirms they all do.
This commit is contained in:
Gleb Smirnoff 2024-06-20 10:53:31 -07:00
parent 39afff09c5
commit 3beb43dd4f
2 changed files with 5 additions and 9 deletions

View file

@ -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 ){

View file

@ -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);