Skip to content

Commit 5aaf6a8

Browse files
tobluxMiklos Szeredi
authored andcommitted
ovl: Replace offsetof() with struct_size() in ovl_cache_entry_new()
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 8a39f1c commit 5aaf6a8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/overlayfs/readdir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/security.h>
1414
#include <linux/cred.h>
1515
#include <linux/ratelimit.h>
16+
#include <linux/overflow.h>
1617
#include "overlayfs.h"
1718

1819
struct ovl_cache_entry {
@@ -147,9 +148,8 @@ static struct ovl_cache_entry *ovl_cache_entry_new(struct ovl_readdir_data *rdd,
147148
u64 ino, unsigned int d_type)
148149
{
149150
struct ovl_cache_entry *p;
150-
size_t size = offsetof(struct ovl_cache_entry, name[len + 1]);
151151

152-
p = kmalloc(size, GFP_KERNEL);
152+
p = kmalloc(struct_size(p, name, len + 1), GFP_KERNEL);
153153
if (!p)
154154
return NULL;
155155

0 commit comments

Comments
 (0)