[PATCH v2 1/1] Fix kernel memcpy() warnings about exceeding array boundaries

Chris Kirby <[email protected]> Mon, 2 Mar 2026 14:44:26 -0600
Newsgroups dev.linux.lists.rpdfs-devel
Message-ID <84e11e22041d5cb5e365ec017a52ba27aa05d48e.1772484108.git.ckirby@versity.com>
Fix kernel memcpy() warnings about exceeding array boundaries
when using flex arrays.

Use DECLARE_FLEX_ARRAY in a union to correctly align both
struct rpdfs_dirent and struct rpdfs_xattr.

Signed-off-by: Chris Kirby <[email protected]>
---
 fs/rpdfs/format-block.h | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/rpdfs/format-block.h b/fs/rpdfs/format-block.h
index e594d58a55a9..a5e9dd9ebe12 100644
--- a/fs/rpdfs/format-block.h
+++ b/fs/rpdfs/format-block.h
@@ -177,7 +177,10 @@ struct rpdfs_dirent {
 	struct rpdfs_ino_gen ig; /* inode number and generation */
 	__u8 pers_dtype; /* rpdfs persistent directory entry type */
 	__u8 name_len; /* no null termination */
-	__u8 name[6]; /* definition pads to alignment, stored can be smaller */
+	union {
+		__u8 pad[6]; /* pad to alignment, stored can be smaller */
+		DECLARE_FLEX_ARRAY(__u8, name);
+	};
 };
 
 /* max dirent name length, without null term */
@@ -210,13 +213,15 @@ struct rpdfs_dirent {
 /*
  * xattrs are currently implemented as btree items, whose keys are the
  * hash of the name combined with the xattr_create_counter value in the
- * inode, which makes the keys unique - no collisions. name is padded to
- * alignment but will be bigger.
+ * inode, which makes the keys unique - no collisions.
  */
 struct rpdfs_xattr {
 	__le16 val_len;
 	__u8 name_len;
-	__u8 name[1];
+	union {
+		__u8 pad[1]; /* pad to alignment, stored will be bigger */
+		DECLARE_FLEX_ARRAY(__u8, name);
+	};
 };
 
 /*
-- 
2.53.0