(new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) &&
                                    (new_cpup->phys_id == cpup->phys_id))
                                        goto found_same;
-                               new_cpu = cpumask_next(
-                                       new_cpu, cpu_present_mask);
-                               if (new_cpu >= nr_cpu_ids)
-                                       new_cpu = first_cpu;
+                               new_cpu = lpfc_next_present_cpu(new_cpu);
                        }
                        /* At this point, we leave the CPU as unassigned */
                        continue;
                         * chance of having multiple unassigned CPU entries
                         * selecting the same IRQ.
                         */
-                       start_cpu = cpumask_next(new_cpu, cpu_present_mask);
-                       if (start_cpu >= nr_cpu_ids)
-                               start_cpu = first_cpu;
+                       start_cpu = lpfc_next_present_cpu(new_cpu);
 
                        lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
                                        "3337 Set Affinity: CPU %d "
                                if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) &&
                                    (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY))
                                        goto found_any;
-                               new_cpu = cpumask_next(
-                                       new_cpu, cpu_present_mask);
-                               if (new_cpu >= nr_cpu_ids)
-                                       new_cpu = first_cpu;
+                               new_cpu = lpfc_next_present_cpu(new_cpu);
                        }
                        /* We should never leave an entry unassigned */
                        lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
                         * chance of having multiple unassigned CPU entries
                         * selecting the same IRQ.
                         */
-                       start_cpu = cpumask_next(new_cpu, cpu_present_mask);
-                       if (start_cpu >= nr_cpu_ids)
-                               start_cpu = first_cpu;
+                       start_cpu = lpfc_next_present_cpu(new_cpu);
 
                        lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
                                        "3338 Set Affinity: CPU %d "
                            new_cpup->core_id == cpup->core_id) {
                                goto found_hdwq;
                        }
-                       new_cpu = cpumask_next(new_cpu, cpu_present_mask);
-                       if (new_cpu >= nr_cpu_ids)
-                               new_cpu = first_cpu;
+                       new_cpu = lpfc_next_present_cpu(new_cpu);
                }
 
                /* If we can't match both phys_id and core_id,
                        if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY &&
                            new_cpup->phys_id == cpup->phys_id)
                                goto found_hdwq;
-
-                       new_cpu = cpumask_next(new_cpu, cpu_present_mask);
-                       if (new_cpu >= nr_cpu_ids)
-                               new_cpu = first_cpu;
+                       new_cpu = lpfc_next_present_cpu(new_cpu);
                }
 
                /* Otherwise just round robin on cfg_hdw_queue */
                goto logit;
  found_hdwq:
                /* We found an available entry, copy the IRQ info */
-               start_cpu = cpumask_next(new_cpu, cpu_present_mask);
-               if (start_cpu >= nr_cpu_ids)
-                       start_cpu = first_cpu;
+               start_cpu = lpfc_next_present_cpu(new_cpu);
                cpup->hdwq = new_cpup->hdwq;
  logit:
                lpfc_printf_log(phba, KERN_INFO, LOG_INIT,