* [PATCH] ovl: Replace offsetof() with struct_size() in ovl_cache_entry_new()
@ 2025-05-03 9:15 Thorsten Blum
0 siblings, 0 replies; only message in thread
From: Thorsten Blum @ 2025-05-03 9:15 UTC (permalink / raw)
To: Miklos Szeredi, Amir Goldstein; +Cc: Thorsten Blum, linux-unionfs, linux-kernel
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>
---
fs/overlayfs/readdir.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c
index 881ec5592da5..1ae4a488af92 100644
--- a/fs/overlayfs/readdir.c
+++ b/fs/overlayfs/readdir.c
@@ -147,9 +147,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;
--
2.49.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2025-05-03 10:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-03 9:15 [PATCH] ovl: Replace offsetof() with struct_size() in ovl_cache_entry_new() Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).