[Concept,11/16] ext4l: Add linux/overflow.h and move struct_size
Commit Message
From: Simon Glass <simon.glass@canonical.com>
Create include/linux/overflow.h with the struct_size() macro that
calculates the size of a structure with a trailing flexible array
member.
Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---
fs/ext4l/ext4_uboot.h | 4 ++--
include/linux/overflow.h | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+), 2 deletions(-)
create mode 100644 include/linux/overflow.h
@@ -923,8 +923,8 @@ extern struct inode *iget_locked(struct super_block *sb, unsigned long ino);
ssize_t generic_read_dir(struct file *f, char __user *buf, size_t count,
loff_t *ppos);
-/* struct_size helper */
-#define struct_size(p, member, count) (sizeof(*(p)) + sizeof((p)->member[0]) * (count))
+/* struct_size - use linux/overflow.h */
+#include <linux/overflow.h>
/* file_operations - extended for dir.c */
struct file_operations {
new file mode 100644
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Overflow checking utilities
+ *
+ * Based on Linux overflow.h
+ */
+#ifndef _LINUX_OVERFLOW_H
+#define _LINUX_OVERFLOW_H
+
+#include <linux/types.h>
+
+/**
+ * struct_size() - Calculate size of structure with trailing array member
+ * @p: Pointer to the structure
+ * @member: Name of the array member
+ * @count: Number of elements in the array
+ *
+ * Return: Total size of the structure including @count array elements
+ */
+#define struct_size(p, member, count) \
+ (sizeof(*(p)) + sizeof((p)->member[0]) * (count))
+
+#endif /* _LINUX_OVERFLOW_H */