]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
objpool: rework objpool_pop()
authorYury Norov <yury.norov@gmail.com>
Tue, 28 Jan 2025 16:46:30 +0000 (11:46 -0500)
committerYury Norov <yury.norov@gmail.com>
Tue, 18 Feb 2025 16:51:22 +0000 (11:51 -0500)
The function has to track number of iterations to prevent an infinite
loop. for_each_cpu_wrap() macro takes care of it, which simplifies user
code.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
include/linux/objpool.h

index cb1758eaa2d38438b73182c22e2329def7b0c499..b713a1fe7521b0f38abeacee3b794203fe98073a 100644 (file)
@@ -170,17 +170,16 @@ static inline void *objpool_pop(struct objpool_head *pool)
 {
        void *obj = NULL;
        unsigned long flags;
-       int i, cpu;
+       int start, cpu;
 
        /* disable local irq to avoid preemption & interruption */
        raw_local_irq_save(flags);
 
-       cpu = raw_smp_processor_id();
-       for (i = 0; i < pool->nr_possible_cpus; i++) {
+       start = raw_smp_processor_id();
+       for_each_possible_cpu_wrap(cpu, start) {
                obj = __objpool_try_get_slot(pool, cpu);
                if (obj)
                        break;
-               cpu = cpumask_next_wrap(cpu, cpu_possible_mask, -1, 1);
        }
        raw_local_irq_restore(flags);