]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
cleanup: add a scoped version of CLASS()
authorChristian Brauner <brauner@kernel.org>
Fri, 11 Jul 2025 13:47:48 +0000 (15:47 +0200)
committerChristian Brauner <brauner@kernel.org>
Fri, 11 Jul 2025 14:01:07 +0000 (16:01 +0200)
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 <brauner@kernel.org>
include/linux/cleanup.h

index 7093e1d08af071363245d7b396ab6955a6c91a20..bee606bebaca3a55dc9274484a1cdb832eaef501 100644 (file)
@@ -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):