From: Johannes Berg <johannes.berg@xxxxxxxxx> For get_random_u32_inclusive() we need get_random_u32_below(), implement it with prandom_u32_max() as it used to be in iwlwifi. Reviewed-by: Gregory Greenman <gregory.greenman@xxxxxxxxx> Signed-off-by: Johannes Berg <johannes.berg@xxxxxxxxx> --- backport/backport-include/linux/random.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 backport/backport-include/linux/random.h diff --git a/backport/backport-include/linux/random.h b/backport/backport-include/linux/random.h new file mode 100644 index 000000000000..0a247321785a --- /dev/null +++ b/backport/backport-include/linux/random.h @@ -0,0 +1,21 @@ +#ifndef __BACKPORT_RANDOM_H +#define __BACKPORT_RANDOM_H +#include_next <linux/random.h> +#include <linux/version.h> + +#if LINUX_VERSION_IS_LESS(6,2,0) +static inline u32 get_random_u32_below(u32 ceil) +{ + return prandom_u32_max(ceil); +} + +static inline u32 get_random_u32_inclusive(u32 floor, u32 ceil) +{ + BUILD_BUG_ON_MSG(__builtin_constant_p(floor) && __builtin_constant_p(ceil) && + (floor > ceil || ceil - floor == U32_MAX), + "get_random_u32_inclusive() must take floor <= ceil"); + return floor + get_random_u32_below(ceil - floor + 1); +} +#endif + +#endif /* __BACKPORT_RANDOM_H */ -- 2.45.1