From: Gregory Greenman <gregory.greenman@xxxxxxxxx> This will be included upstream in 6.4 hopefully. Co-Authored-By: Benjamin Berg <benjamin.berg@xxxxxxxxx> Signed-off-by: Gregory Greenman <gregory.greenman@xxxxxxxxx> Signed-off-by: Johannes Berg <johannes.berg@xxxxxxxxx> --- backport/compat/Makefile | 1 + backport/compat/backport-6.4.c | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 backport/compat/backport-6.4.c diff --git a/backport/compat/Makefile b/backport/compat/Makefile index 3c8430bc4958..62dfc62f7b46 100644 --- a/backport/compat/Makefile +++ b/backport/compat/Makefile @@ -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 diff --git a/backport/compat/backport-6.4.c b/backport/compat/backport-6.4.c new file mode 100644 index 000000000000..995c1f1d1b22 --- /dev/null +++ b/backport/compat/backport-6.4.c @@ -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) */ -- 2.45.1