From: Christian Brauner Date: Fri, 11 Jul 2025 13:47:48 +0000 (+0200) Subject: cleanup: add a scoped version of CLASS() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c21c5f22d0701ac6c1cafc0e8de4bf42e5c53e5;p=thirdparty%2Fkernel%2Fstable.git cleanup: add a scoped version of CLASS() This will make it possible to use: scoped_class() { } constructs to limit variables to certain scopes and still perform auto-cleanup. Signed-off-by: Christian Brauner --- diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h index 7093e1d08af07..bee606bebaca3 100644 --- a/include/linux/cleanup.h +++ b/include/linux/cleanup.h @@ -277,6 +277,14 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \ class_##_name##_t var __cleanup(class_##_name##_destructor) = \ class_##_name##_constructor +#define scoped_class(_name, var, args) \ + for (CLASS(_name, var)(args); \ + __guard_ptr(_name)(&var) || !__is_cond_ptr(_name); \ + ({ goto _label; })) \ + if (0) { \ +_label: \ + break; \ + } else /* * DEFINE_GUARD(name, type, lock, unlock):