@@ -16,6 +16,7 @@ compat-$(CPTCFG_KERNEL_5_10) += backport-5.10.o
compat-$(CPTCFG_KERNEL_5_11) += backport-5.11.o
compat-$(CPTCFG_KERNEL_5_13) += backport-5.13.o
compat-$(CPTCFG_KERNEL_5_15) += backport-5.15.o
+compat-$(CPTCFG_KERNEL_6_4) += backport-6.4.o
compat-$(CPTCFG_BPAUTO_BUILD_SYSTEM_DATA_VERIFICATION) += verification/verify.o
compat-$(CPTCFG_BPAUTO_BUILD_SYSTEM_DATA_VERIFICATION) += verification/pkcs7.asn1.o
new file mode 100644
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#if LINUX_VERSION_IS_GEQ(6,2,0) && defined(CONFIG_KUNIT)
+#include <kunit/test.h>
+
+struct kunit_auto_cleanup {
+ struct kunit_resource resource;
+ kunit_cleanup_t cleanup_func;
+};
+
+static void kunit_auto_cleanup_free(struct kunit_resource *res)
+{
+ struct kunit_auto_cleanup *cleanup;
+
+ cleanup = container_of(res, struct kunit_auto_cleanup, resource);
+
+ cleanup->cleanup_func(cleanup->resource.data);
+}
+
+void kunit_add_cleanup(struct kunit *test, kunit_cleanup_t cleanup_func,
+ const void *data, gfp_t internal_gfp)
+{
+ struct kunit_auto_cleanup *res;
+
+ KUNIT_ASSERT_NOT_NULL_MSG(test, cleanup_func,
+ "Cleanup function must not be NULL");
+
+ res = kzalloc(sizeof(*res), internal_gfp);
+ if (!res) {
+ cleanup_func(data);
+ KUNIT_ASSERT_FAILURE(test, "Could not allocate resource for cleanup");
+ }
+
+ res->cleanup_func = cleanup_func;
+ res->resource.should_kfree = true;
+
+ /* Cannot fail as init is NULL */
+ __kunit_add_resource(test, NULL, kunit_auto_cleanup_free,
+ &res->resource, (void *)data);
+}
+EXPORT_SYMBOL_GPL(kunit_add_cleanup);
+#endif /* LINUX_VERSION_IS_GEQ(6,2,0) */