[PATCH 04/20] headers: add get_random_u32_inclusive() for kernels < 6.2

Yi Cong <[email protected]> Wed, 24 Jun 2026 15:38:28 +0800
Newsgroups org.kernel.vger.backports
Message-ID <[email protected]>
From: Yi Cong <[email protected]>

get_random_u32_inclusive() was introduced in v6.2.  Provide it as a
static inline backed by the older prandom_u32_max() helper.

Signed-off-by: Yi Cong <[email protected]>
---
 backport/backport-include/linux/random.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/backport/backport-include/linux/random.h b/backport/backport-include/linux/random.h
index f4fd47dc..6437d55e 100644
--- a/backport/backport-include/linux/random.h
+++ b/backport/backport-include/linux/random.h
@@ -15,4 +15,11 @@ static inline u16 get_random_u16(void)
 }
 #endif
 
+#if LINUX_VERSION_IS_LESS(6,2,0)
+static inline u32 get_random_u32_inclusive(u32 floor, u32 ceiling)
+{
+	return prandom_u32_max(ceiling - floor + 1) + floor;
+}
+#endif
+
 #endif /* __BACKPORT_RANDOM_H */
-- 
2.43.0