Skip to content

Commit 7314166

Browse files
tobluxMiklos Szeredi
authored andcommitted
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 <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 5aaf6a8 commit 7314166

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/overlayfs/util.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/uuid.h>
1616
#include <linux/namei.h>
1717
#include <linux/ratelimit.h>
18+
#include <linux/overflow.h>
1819
#include "overlayfs.h"
1920

2021
/* 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)
145146

146147
struct ovl_entry *ovl_alloc_entry(unsigned int numlower)
147148
{
148-
size_t size = offsetof(struct ovl_entry, __lowerstack[numlower]);
149-
struct ovl_entry *oe = kzalloc(size, GFP_KERNEL);
149+
struct ovl_entry *oe;
150150

151+
oe = kzalloc(struct_size(oe, __lowerstack, numlower), GFP_KERNEL);
151152
if (oe)
152153
oe->__numlower = numlower;
153154

0 commit comments

Comments
 (0)