summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Blum <thorsten.blum@linux.dev>2025-05-03 13:52:44 +0200
committerMiklos Szeredi <mszeredi@redhat.com>2025-05-05 12:47:57 +0200
commit7314166ee7592513c77cfbb8ff579f376039f9c4 (patch)
tree3fedef06cc2ec6748298af8b4e9f76e080586659
parent5aaf6a8cc3305e1000417f6fac9d131c47db9117 (diff)
ovl: Replace offsetof() with struct_size() in ovl_stack_free()
Compared to offsetof(), struct_size() provides additional compile-time checks for structs with flexible arrays (e.g., __must_be_array()). No functional changes intended. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
-rw-r--r--fs/overlayfs/util.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
index 5d6b60d56c27..dcccb4b4a66c 100644
--- a/fs/overlayfs/util.c
+++ b/fs/overlayfs/util.c
@@ -15,6 +15,7 @@
#include <linux/uuid.h>
#include <linux/namei.h>
#include <linux/ratelimit.h>
+#include <linux/overflow.h>
#include "overlayfs.h"
/* Get write access to upper mnt - may fail if upper sb was remounted ro */
@@ -145,9 +146,9 @@ void ovl_stack_free(struct ovl_path *stack, unsigned int n)
struct ovl_entry *ovl_alloc_entry(unsigned int numlower)
{
- size_t size = offsetof(struct ovl_entry, __lowerstack[numlower]);
- struct ovl_entry *oe = kzalloc(size, GFP_KERNEL);
+ struct ovl_entry *oe;
+ oe = kzalloc(struct_size(oe, __lowerstack, numlower), GFP_KERNEL);
if (oe)
oe->__numlower = numlower;