lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu,  6 Oct 2022 13:21:09 +0100
From:   Valentin Schneider <vschneid@...hat.com>
To:     linux-block@...r.kernel.org, linux-kernel@...r.kernel.org
Cc:     Jens Axboe <axboe@...nel.dk>, Yury Norov <yury.norov@...il.com>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>
Subject: [RFC PATCH bitmap-for-next 1/4] lib/cpumask: Generate cpumask_next_wrap() body with a macro

In preparation of introducing cpumask_next_and_wrap(), gather the
would-be-boiler-plate logic into a macro, as was done in

e79864f3164c ("lib/find_bit: optimize find_next_bit() functions")

Signed-off-by: Valentin Schneider <vschneid@...hat.com>
---
 lib/cpumask.c | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/lib/cpumask.c b/lib/cpumask.c
index c7c392514fd3..6e576485c84f 100644
--- a/lib/cpumask.c
+++ b/lib/cpumask.c
@@ -7,8 +7,27 @@
 #include <linux/memblock.h>
 #include <linux/numa.h>
 
+#define CPUMASK_NEXT_WRAP(FETCH_NEXT, n, start, wrap)			\
+({									\
+	unsigned int next;						\
+									\
+again:									\
+	next = (FETCH_NEXT);						\
+									\
+	if (wrap && n < start && next >= start) {			\
+		next = nr_cpumask_bits;					\
+	} else if (next >= nr_cpumask_bits) {				\
+		wrap = true;						\
+		n = -1;							\
+		goto again;						\
+	}								\
+									\
+	next;								\
+})
+
 /**
- * cpumask_next_wrap - helper to implement for_each_cpu_wrap
+ * cpumask_next_wrap - Get the next CPU in a mask, starting from a given
+ *                     position and wrapping around to visit all CPUs.
  * @n: the cpu prior to the place to search
  * @mask: the cpumask pointer
  * @start: the start point of the iteration
@@ -21,21 +40,7 @@
  */
 unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap)
 {
-	unsigned int next;
-
-again:
-	next = cpumask_next(n, mask);
-
-	if (wrap && n < start && next >= start) {
-		return nr_cpumask_bits;
-
-	} else if (next >= nr_cpumask_bits) {
-		wrap = true;
-		n = -1;
-		goto again;
-	}
-
-	return next;
+	return CPUMASK_NEXT_WRAP(cpumask_next(n, mask), n, start, wrap);
 }
 EXPORT_SYMBOL(cpumask_next_wrap);
 
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ