]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ovl: Replace offsetof() with struct_size() in ovl_cache_entry_new()
authorThorsten Blum <thorsten.blum@linux.dev>
Sat, 3 May 2025 11:52:03 +0000 (13:52 +0200)
committerMiklos Szeredi <mszeredi@redhat.com>
Mon, 5 May 2025 10:47:30 +0000 (12:47 +0200)
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>
fs/overlayfs/readdir.c

index 881ec5592da52dfb27a588496582e7084b2fbd3b..efe4700c797e2dce0e3bf8e771c8c393ac5af692 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/security.h>
 #include <linux/cred.h>
 #include <linux/ratelimit.h>
+#include <linux/overflow.h>
 #include "overlayfs.h"
 
 struct ovl_cache_entry {
@@ -147,9 +148,8 @@ static struct ovl_cache_entry *ovl_cache_entry_new(struct ovl_readdir_data *rdd,
                                                   u64 ino, unsigned int d_type)
 {
        struct ovl_cache_entry *p;
-       size_t size = offsetof(struct ovl_cache_entry, name[len + 1]);
 
-       p = kmalloc(size, GFP_KERNEL);
+       p = kmalloc(struct_size(p, name, len + 1), GFP_KERNEL);
        if (!p)
                return NULL;