[Concept,01/23] linux: random: Add get_random_u32_below and prandom_u32_max

Message ID 20260119061529.3383191-2-sjg@u-boot.org
State New
Headers
Series Reduce ext4_uboot.h by moving definitions to linux headers |

Commit Message

Simon Glass Jan. 19, 2026, 6:14 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Add get_random_u32_below() and prandom_u32_max() stub macros to
linux/random.h for filesystem code that uses random number generation.

Update ext4_uboot.h to use linux/random.h instead of duplicating
these definitions.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 fs/ext4l/ext4_uboot.h  |  8 +++-----
 include/linux/random.h | 25 ++++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 6 deletions(-)
  

Patch

diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h
index 3c6b3ca5507..4fb8f9111b0 100644
--- a/fs/ext4l/ext4_uboot.h
+++ b/fs/ext4l/ext4_uboot.h
@@ -252,8 +252,8 @@  struct buffer_head *sb_getblk(struct super_block *sb, sector_t block);
 
 /* d_inode is now in linux/dcache.h */
 
-/* Random number functions */
-#define get_random_u32_below(max)		(0)
+/* Random number functions - use linux/random.h */
+#include <linux/random.h>
 
 /* Buffer cache operations */
 #define sb_find_get_block(sb, block)		((struct buffer_head *)NULL)
@@ -1267,9 +1267,7 @@  int ext4_fill_super(struct super_block *sb, struct fs_context *fc);
 int ext4_commit_super(struct super_block *sb);
 void ext4_unregister_li_request(struct super_block *sb);
 
-/* prandom */
-#define get_random_u32()		0
-#define prandom_u32_max(max)		0
+/* prandom - get_random_u32, prandom_u32_max are in linux/random.h */
 
 /* ctype */
 #include <linux/ctype.h>
diff --git a/include/linux/random.h b/include/linux/random.h
index cb09c6c6b05..1a9de842a4c 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -1,6 +1,9 @@ 
 /* SPDX-License-Identifier: GPL-2.0 */
 /*
- * Stub definitions for random number generation.
+ * Random number generation definitions for U-Boot
+ *
+ * Based on Linux random.h - random number generation.
+ * U-Boot stub - returns constant values.
  */
 #ifndef _LINUX_RANDOM_H
 #define _LINUX_RANDOM_H
@@ -12,4 +15,24 @@ 
 #define get_random_u32()		0
 #define get_random_u64()		0ULL
 
+/**
+ * get_random_u32_below() - get random number below a ceiling
+ * @ceil: upper bound (exclusive)
+ *
+ * U-Boot stub - always returns 0.
+ *
+ * Return: random value in [0, ceil)
+ */
+#define get_random_u32_below(ceil)	(0)
+
+/**
+ * prandom_u32_max() - get random number up to a maximum
+ * @max: upper bound (inclusive)
+ *
+ * U-Boot stub - always returns 0.
+ *
+ * Return: random value in [0, max]
+ */
+#define prandom_u32_max(max)		(0)
+
 #endif /* _LINUX_RANDOM_H */