aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linuxkpi/common
diff options
context:
space:
mode:
authorBjoern A. Zeeb <bz@FreeBSD.org>2024-09-28 22:38:03 +0000
committerBjoern A. Zeeb <bz@FreeBSD.org>2024-10-14 17:45:42 +0000
commitfa81baa307da9a0055d7d08f6d141ea310f067ed (patch)
treef6604557ae6ddbeaa3afcf0df2ab063a25e04914 /sys/compat/linuxkpi/common
parente69e172d40585cfbcfdb28433cec523ca4867cf1 (diff)
downloadsrc-fa81baa307da9a0055d7d08f6d141ea310f067ed.tar.gz
src-fa81baa307da9a0055d7d08f6d141ea310f067ed.zip
LinuxKPI: add cleanup.h for guard DEFINE_GUARD/guard.
iwlwifi v6.11 started to use guard(). _T in the implementation needs to be exposed to the driver which uses it in DEFINE_GUARD(). Given this is the first instance of attribute(cleanup) in the tree: - gcc has support for it since at least 2003-06-04 (0bfa5f65bfb186f10d43304946fd7fcd69988732) - llvm gained support on 2009-01-31 (d277d790e0f6f23043397ba919619b5c3e157ff3, llvm-svn 63462). Sponsored by: The FreeBSD Foundation MFC after: 3 days Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D46843
Diffstat (limited to 'sys/compat/linuxkpi/common')
-rw-r--r--sys/compat/linuxkpi/common/include/linux/cleanup.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/cleanup.h b/sys/compat/linuxkpi/common/include/linux/cleanup.h
new file mode 100644
index 000000000000..01f234f0cbe7
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/cleanup.h
@@ -0,0 +1,46 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 The FreeBSD Foundation
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ */
+
+#ifndef _LINUXKPI_LINUX_CLEANUP_H
+#define _LINUXKPI_LINUX_CLEANUP_H
+
+#define __cleanup(_f) __attribute__((__cleanup__(_f)))
+
+/*
+ * Note: "_T" are special as they are exposed into common code for
+ * statements. Extra care should be taken when changing the code.
+ */
+#define DEFINE_GUARD(_n, _dt, _lock, _unlock) \
+ \
+ typedef _dt guard_ ## _n ## _t; \
+ \
+ static inline _dt \
+ guard_ ## _n ## _create( _dt _T) \
+ { \
+ _dt c; \
+ \
+ c = ({ _lock; _T; }); \
+ return (c); \
+ } \
+ \
+ static inline void \
+ guard_ ## _n ## _destroy(_dt *t) \
+ { \
+ _dt _T; \
+ \
+ _T = *t; \
+ if (_T) { _unlock; }; \
+ }
+
+/* We need to keep these calls unique. */
+#define guard(_n) \
+ guard_ ## _n ## _t guard_ ## _n ## _ ## __COUNTER__ \
+ __cleanup(guard_ ## _n ## _destroy) = guard_ ## _n ## _create
+
+#endif /* _LINUXKPI_LINUX_CLEANUP_H */