Skip to content

Commit 5c21c5f

Browse files
committed
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 <[email protected]>
1 parent a6ed569 commit 5c21c5f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/linux/cleanup.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \
277277
class_##_name##_t var __cleanup(class_##_name##_destructor) = \
278278
class_##_name##_constructor
279279

280+
#define scoped_class(_name, var, args) \
281+
for (CLASS(_name, var)(args); \
282+
__guard_ptr(_name)(&var) || !__is_cond_ptr(_name); \
283+
({ goto _label; })) \
284+
if (0) { \
285+
_label: \
286+
break; \
287+
} else
280288

281289
/*
282290
* DEFINE_GUARD(name, type, lock, unlock):

0 commit comments

Comments
 (0)