Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpumask: Add initialiser to use cleanup helpers

Now we can simplify a code that allocates cpumasks for local needs.

Automatic variables have to be initialized at declaration, or at least
before any possibility for the logic to return, so that compiler
wouldn't try to call an associate destructor function on a random stack
number.

Because cpumask_var_t, depending on the CPUMASK_OFFSTACK config, is
either a pointer or an array, we have to have a macro for initialization.

So define a CPUMASK_VAR_NULL macro, which allows to init struct cpumask
pointer with NULL when CPUMASK_OFFSTACK is enabled, and effectively a
no-op when CPUMASK_OFFSTACK is disabled (initialisation optimised out
with -O2).

Signed-off-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
Link: https://patch.msgid.link/20251120145653.296659-7-gmonaco@redhat.com

authored by

Yury Norov and committed by
Thomas Gleixner
b5665100 185bccc7

+2
+2
include/linux/cpumask.h
··· 1005 1005 1006 1006 #define this_cpu_cpumask_var_ptr(x) this_cpu_read(x) 1007 1007 #define __cpumask_var_read_mostly __read_mostly 1008 + #define CPUMASK_VAR_NULL NULL 1008 1009 1009 1010 bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node); 1010 1011 ··· 1052 1051 1053 1052 #define this_cpu_cpumask_var_ptr(x) this_cpu_ptr(x) 1054 1053 #define __cpumask_var_read_mostly 1054 + #define CPUMASK_VAR_NULL {} 1055 1055 1056 1056 static __always_inline bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags) 1057 1057 {