Re: [PATCH v8 11/14] module: Reorder functions

From
Peter Zijlstra <peterz@infradead.org>
Date
2021-12-03 10:23:59
Also in
linux-hardening, linux-kbuild, live-patching, lkml, llvm
Reply to
Alexander Lobakin, 2021-12-02
On Thu, Dec 02, 2021 at 11:32:11PM +0100, Alexander Lobakin wrote:
quoted hunk ↗ jump to hunk
+/*
+ * shuffle_text_list()
+ * Use a Fisher Yates algorithm to shuffle a list of text sections.
+ */
+static void shuffle_text_list(Elf_Shdr **list, int size)
+{
+	u32 i, j;
+
+	for (i = size - 1; i > 0; i--) {
+		/*
+		 * pick a random index from 0 to i
+		 */
+		j = get_random_u32() % (i + 1);
+
+		swap(list[i], list[j]);
+	}
+}
I'm sure I've seen pretty much that exact function earlier in this
series; does we really need two of them?

#define shuffle_me_harder(_base, _size, _nr)				\
do {									\
	struct { unsigned char _[_size]; } _t, *_a = (void *)(_base);	\
	int _i, _j;							\
	for (_i = (_nr)-1; _i > 0; _i--) {				\
		_j = get_random_u32() % (_i + 1);			\
		_t = _a[_i];						\
		_a[_i] = _a[_j];					\
		_a[_j] = _t;						\
	}								\
} while (0)

#define shuffle_array(_array)	shuffle_me_harder(_array, sizeof(_array[0]), sizeof(_array)/sizeof(_array[0]))

Or something like that...
Thread (30 messages) 30 messages, 4 authors, last reply 2021-12-07
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help