[PATCH v3 1/5] kernel: Add helper macros for loop unrolling
Kees Cook
keescook at chromium.org
Wed Sep 20 15:46:16 UTC 2023
On Mon, Sep 18, 2023 at 11:24:55PM +0200, KP Singh wrote:
> This helps in easily initializing blocks of code (e.g. static calls and
> keys).
>
> UNROLL(N, MACRO, __VA_ARGS__) calls MACRO N times with the first
> argument as the index of the iteration. This allows string pasting to
> create unique tokens for variable names, function calls etc.
>
> As an example:
>
> #include <linux/unroll.h>
>
> #define MACRO(N, a, b) \
> int add_##N(int a, int b) \
> { \
> return a + b + N; \
> }
>
> UNROLL(2, MACRO, x, y)
>
> expands to:
>
> int add_0(int x, int y)
> {
> return x + y + 0;
> }
>
> int add_1(int x, int y)
> {
> return x + y + 1;
> }
>
> Signed-off-by: KP Singh <kpsingh at kernel.org>
A handy bit of macro fun to have. :)
Reviewed-by: Kees Cook <keescook at chromium.org>
--
Kees Cook
More information about the Linux-security-module-archive
mailing list