[Concept,08/12] linux: Add ratelimit.h header with rate limiting stubs

Message ID 20260118133734.8.44e6459f58d96077c114c70af004835ed34c6be8@changeid
State New
Headers
Series ext4l: Continue reducing ext4_uboot.h size with more headers |

Commit Message

Simon Glass Jan. 18, 2026, 8:37 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Create linux/ratelimit.h with ratelimit_state structure and rate
limiting operation stubs. Rate limiting is not needed in U-Boot.

Update ext4_uboot.h to use the new header 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     | 19 +++++--------------
 include/linux/ratelimit.h | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 14 deletions(-)
 create mode 100644 include/linux/ratelimit.h
  

Patch

diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h
index 102f03fe002..f6883d888f4 100644
--- a/fs/ext4l/ext4_uboot.h
+++ b/fs/ext4l/ext4_uboot.h
@@ -384,10 +384,8 @@  typedef int (get_block_t)(struct inode *inode, sector_t iblock,
 /* crc32c - from linux/crc32c.h */
 #include <linux/crc32c.h>
 
-/* ratelimit_state - stub */
-struct ratelimit_state {
-	int dummy;
-};
+/* ratelimit_state - use linux/ratelimit.h */
+#include <linux/ratelimit.h>
 
 /* fscrypt_dummy_policy and qstr are now in ext4_fscrypt.h */
 
@@ -869,12 +867,7 @@  static inline int in_range(unsigned long val, unsigned long start,
 
 /* percpu_counter_init/destroy are in linux/percpu_counter.h */
 
-/* ratelimit macros */
-#define DEFAULT_RATELIMIT_INTERVAL	(5 * 1000)
-#define DEFAULT_RATELIMIT_BURST		10
-#define DEFINE_RATELIMIT_STATE(name, interval, burst) \
-	int name __attribute__((unused)) = 0
-#define __ratelimit(state)		({ (void)(state); 1; })
+/* ratelimit macros are now in linux/ratelimit.h */
 
 /* SEQ_START_TOKEN is in linux/seq_file.h */
 
@@ -1364,8 +1357,7 @@  int trylock_buffer(struct buffer_head *bh);
 /* Trace stubs for super.c - declaration for stub.c implementation */
 void trace_ext4_error(struct super_block *sb, const char *func, unsigned int line);
 
-/* Ratelimiting - declaration for stub.c */
-int ___ratelimit(struct ratelimit_state *rs, const char *func);
+/* ___ratelimit is now in linux/ratelimit.h */
 
 /* Filesystem notification - declaration for stub.c */
 void fsnotify_sb_error(struct super_block *sb, struct inode *inode, int error);
@@ -1502,8 +1494,7 @@  static inline void super_set_uuid(struct super_block *sb, const u8 *uuid,
 
 /* strreplace is in linux/string.h */
 
-/* Ratelimit - declaration for stub.c */
-void ratelimit_state_init(void *rs, int interval, int burst);
+/* ratelimit_state_init is now in linux/ratelimit.h */
 
 /* Block device operations - declarations for stub.c */
 void bdev_fput(void *file);
diff --git a/include/linux/ratelimit.h b/include/linux/ratelimit.h
new file mode 100644
index 00000000000..319f794f059
--- /dev/null
+++ b/include/linux/ratelimit.h
@@ -0,0 +1,35 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Rate limit definitions for U-Boot
+ *
+ * Based on Linux ratelimit.h - rate limiting for messages.
+ * U-Boot stubs - rate limiting not needed.
+ */
+#ifndef _LINUX_RATELIMIT_H
+#define _LINUX_RATELIMIT_H
+
+/**
+ * struct ratelimit_state - rate limiter state
+ *
+ * U-Boot stub - rate limiting not supported.
+ */
+struct ratelimit_state {
+	int dummy;
+};
+
+/* Default rate limit parameters */
+#define DEFAULT_RATELIMIT_INTERVAL	(5 * 1000)
+#define DEFAULT_RATELIMIT_BURST		10
+
+/* Define a rate limit state variable */
+#define DEFINE_RATELIMIT_STATE(name, interval, burst) \
+	int name __attribute__((unused)) = 0
+
+/* Rate limiting operations - all return true (allow) */
+#define __ratelimit(state)		({ (void)(state); 1; })
+
+/* Rate limit functions - implemented in stub.c */
+int ___ratelimit(struct ratelimit_state *rs, const char *func);
+void ratelimit_state_init(void *rs, int interval, int burst);
+
+#endif /* _LINUX_RATELIMIT_H */