Skip to content

Commit b566510

Browse files
YuryNorovKAGA-KOKO
authored andcommitted
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
1 parent 185bccc commit b566510

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

include/linux/cpumask.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ static __always_inline unsigned int cpumask_size(void)
10051005

10061006
#define this_cpu_cpumask_var_ptr(x) this_cpu_read(x)
10071007
#define __cpumask_var_read_mostly __read_mostly
1008+
#define CPUMASK_VAR_NULL NULL
10081009

10091010
bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
10101011

@@ -1051,6 +1052,7 @@ static __always_inline bool cpumask_available(cpumask_var_t mask)
10511052

10521053
#define this_cpu_cpumask_var_ptr(x) this_cpu_ptr(x)
10531054
#define __cpumask_var_read_mostly
1055+
#define CPUMASK_VAR_NULL {}
10541056

10551057
static __always_inline bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
10561058
{

0 commit comments

Comments
 (0)