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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Dec 02, 2021 at 11:32:11PM +0100, Alexander Lobakin wrote:
> +/*
> + * 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...



[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux