linuxkpi: Add kref_put_lock

Same as kref_put but in addition to calling the rel function it will
acquire the lock first.

Sponsored by: The FreeBSD Foundation
Reviewed by:	hselasky, emaste
Differential Revision:	https://reviews.freebsd.org/D25942
This commit is contained in:
Emmanuel Vadot 2020-08-04 14:44:16 +00:00
parent 16fdd8b7ad
commit 7237a74f3b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=363836

View File

@ -38,6 +38,7 @@
#include <linux/compiler.h>
#include <linux/kernel.h>
#include <linux/mutex.h>
#include <linux/refcount.h>
#include <asm/atomic.h>
@ -77,6 +78,20 @@ kref_put(struct kref *kref, void (*rel)(struct kref *kref))
return 0;
}
static inline int
kref_put_lock(struct kref *kref, void (*rel)(struct kref *kref),
spinlock_t *lock)
{
if (refcount_release(&kref->refcount.counter)) {
spin_lock(lock);
rel(kref);
return (1);
}
return (0);
}
static inline int
kref_sub(struct kref *kref, unsigned int count,
void (*rel)(struct kref *kref))