[PATCH v3 03/57] locking: Introduce __cleanup() based infrastructure

Miguel Ojeda miguel.ojeda.sandonis at gmail.com
Tue Jun 13 17:16:36 UTC 2023


On Mon, Jun 12, 2023 at 11:39 AM Peter Zijlstra <peterz at infradead.org> wrote:
>
> --- a/include/linux/compiler_attributes.h
> +++ b/include/linux/compiler_attributes.h
> @@ -77,6 +77,12 @@
>  #define __attribute_const__             __attribute__((__const__))
>
>  /*
> + *   gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-cleanup-variable-attribute
> + * clang: https://clang.llvm.org/docs/AttributeReference.html#cleanup
> + */
> +#define __cleanup(func)                        __attribute__((__cleanup__(func)))
> +
> +/*
>   * Optional: only supported since gcc >= 9
>   * Optional: not supported by clang
>   *

`cleanup` goes before `const`, but apart from that, for compiler attributes:

    Acked-by: Miguel Ojeda <ojeda at kernel.org>

Thanks for bringing RAII/SBRM to the kernel!

Rust also behaves like the `__cleanup__` attribute, e.g. iterating on
a loop destroys and constructs the variables defined inside the loop.
Also breaking to an outer label/scope.

By the way, maybe some of the macros in `cleanup.h` read a bit better
applying `clang-format` to it.

Cheers,
Miguel



More information about the Linux-security-module-archive mailing list