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

scsi: lpfc: rework lpfc_next_{online,present}_cpu()

lpfc_next_online_cpu() opencodes cpumask_next_and_wrap() by using
a for-loop. Use it and make the lpfc_next_online_cpu() a plain
one-liner.

While there, rework lpfc_next_present_cpu() similarly. Notice that
cpumask_next() followed by cpumask_first() in the worst case of an
empty mask may traverse the mask twice. Cpumask_next_wrap() takes
care of that correctly.

Reviewed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Yury Norov <yury.norov@gmail.com>

+5 -18
+5 -18
drivers/scsi/lpfc/lpfc.h
··· 1715 1715 * Note: If no valid cpu found, then nr_cpu_ids is returned. 1716 1716 * 1717 1717 **/ 1718 - static inline unsigned int 1718 + static __always_inline unsigned int 1719 1719 lpfc_next_online_cpu(const struct cpumask *mask, unsigned int start) 1720 1720 { 1721 - unsigned int cpu_it; 1722 - 1723 - for_each_cpu_wrap(cpu_it, mask, start) { 1724 - if (cpu_online(cpu_it)) 1725 - break; 1726 - } 1727 - 1728 - return cpu_it; 1721 + return cpumask_next_and_wrap(start, mask, cpu_online_mask); 1729 1722 } 1723 + 1730 1724 /** 1731 1725 * lpfc_next_present_cpu - Finds next present CPU after n 1732 1726 * @n: the cpu prior to search ··· 1728 1734 * Note: If no next present cpu, then fallback to first present cpu. 1729 1735 * 1730 1736 **/ 1731 - static inline unsigned int lpfc_next_present_cpu(int n) 1737 + static __always_inline unsigned int lpfc_next_present_cpu(int n) 1732 1738 { 1733 - unsigned int cpu; 1734 - 1735 - cpu = cpumask_next(n, cpu_present_mask); 1736 - 1737 - if (cpu >= nr_cpu_ids) 1738 - cpu = cpumask_first(cpu_present_mask); 1739 - 1740 - return cpu; 1739 + return cpumask_next_wrap(n, cpu_present_mask); 1741 1740 } 1742 1741 1743 1742 /**