From 1a6874e3a411c7876bee55bc631119a2e1cd09a2 Mon Sep 17 00:00:00 2001 From: Emmanuel Vadot Date: Tue, 9 Aug 2022 11:03:34 +0200 Subject: [PATCH] linuxkpi: Add refcount_dec_and_test In Linux this takes a refcount_t argument but in linuxkpi struct kref uses an atomic_t for the refcount and code in drm directly uses this function with a kref so use an atomic_t here. Reviewed by: bz Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D36099 --- sys/compat/linuxkpi/common/include/linux/kref.h | 1 + sys/compat/linuxkpi/common/include/linux/refcount.h | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/kref.h b/sys/compat/linuxkpi/common/include/linux/kref.h index 2c59794f4dd..3b5645bf139 100644 --- a/sys/compat/linuxkpi/common/include/linux/kref.h +++ b/sys/compat/linuxkpi/common/include/linux/kref.h @@ -43,6 +43,7 @@ #include struct kref { + /* XXX In Linux this is a refcount_t */ atomic_t refcount; }; diff --git a/sys/compat/linuxkpi/common/include/linux/refcount.h b/sys/compat/linuxkpi/common/include/linux/refcount.h index 7c055fb3202..6a49da530c0 100644 --- a/sys/compat/linuxkpi/common/include/linux/refcount.h +++ b/sys/compat/linuxkpi/common/include/linux/refcount.h @@ -79,4 +79,15 @@ refcount_dec_and_lock_irqsave(refcount_t *ref, spinlock_t *lock, return (false); } +/* + * struct kref uses atomic_t and not refcount_t so + * we differ from Linux here. + */ +static inline bool +refcount_dec_and_test(atomic_t *r) +{ + + return (atomic_dec_and_test(r)); +} + #endif /* __LINUXKPI_LINUX_REFCOUNT_H__ */