]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sched/membarrier: Modernize membarrier_global_expedited with cleanup guards
authorAniket Gattani <aniketgattani@google.com>
Sun, 3 May 2026 21:22:04 +0000 (21:22 +0000)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 5 May 2026 10:50:48 +0000 (12:50 +0200)
Replace explicit lock/unlock and free calls with scoped guards and
automatic cleanup constructs.

Signed-off-by: Aniket Gattani <aniketgattani@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260503212205.3714217-3-aniketgattani@google.com
kernel/sched/membarrier.c

index 3d88e900a17fc43278bfd361cf086a60152e7fa7..12b68a77630a20c7cded285a9db3a845813b8aa6 100644 (file)
@@ -267,23 +267,19 @@ void membarrier_update_current_mm(struct mm_struct *next_mm)
 
 static int membarrier_global_expedited(void)
 {
+       cpumask_var_t __free(free_cpumask_var) tmpmask = CPUMASK_VAR_NULL;
        int cpu;
-       cpumask_var_t tmpmask;
 
        if (num_online_cpus() == 1)
                return 0;
 
-       /*
-        * Matches memory barriers after rq->curr modification in
-        * scheduler.
-        */
-       smp_mb();       /* system call entry is not a mb. */
-
        if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL))
                return -ENOMEM;
 
+       guard(mb)();
        SERIALIZE_IPI();
-       cpus_read_lock();
+       guard(cpus_read_lock)();
+
        rcu_read_lock();
        for_each_online_cpu(cpu) {
                struct task_struct *p;
@@ -319,15 +315,6 @@ static int membarrier_global_expedited(void)
        smp_call_function_many(tmpmask, ipi_mb, NULL, 1);
        preempt_enable();
 
-       free_cpumask_var(tmpmask);
-       cpus_read_unlock();
-
-       /*
-        * Memory barrier on the caller thread _after_ we finished
-        * waiting for the last IPI. Matches memory barriers before
-        * rq->curr modification in scheduler.
-        */
-       smp_mb();       /* exit from system call is not a mb */
        return 0;
 }