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

From: Miguel Ojeda
Date: Tue Jun 13 2023 - 13:17:05 EST


On Mon, Jun 12, 2023 at 11:39 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> 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@xxxxxxxxxx>

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