* [PATCH v2] ovl: Replace offsetof() with struct_size() in ovl_cache_entry_new()
@ 2025-05-03 11:52 Thorsten Blum
2025-05-05 12:05 ` Miklos Szeredi
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-05-03 11:52 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>
---
Changes in v2:
- Add missing include
- Link to v1: https://lore.kernel.org/lkml/20250503091535.280888-2-thorsten.blum@linux.dev/
---
fs/overlayfs/readdir.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c
index 881ec5592da5..efe4700c797e 100644
--- a/fs/overlayfs/readdir.c
+++ b/fs/overlayfs/readdir.c
@@ -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;
--
2.49.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] ovl: Replace offsetof() with struct_size() in ovl_cache_entry_new()
2025-05-03 11:52 [PATCH v2] ovl: Replace offsetof() with struct_size() in ovl_cache_entry_new() Thorsten Blum
@ 2025-05-05 12:05 ` Miklos Szeredi
0 siblings, 0 replies; 2+ messages in thread
From: Miklos Szeredi @ 2025-05-05 12:05 UTC (permalink / raw)
To: Thorsten Blum; +Cc: Amir Goldstein, linux-unionfs, linux-kernel
On Sat, 3 May 2025 at 13:52, Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> 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>
Applied, thanks.
Miklos
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-05-05 12:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-03 11:52 [PATCH v2] ovl: Replace offsetof() with struct_size() in ovl_cache_entry_new() Thorsten Blum
2025-05-05 12:05 ` Miklos Szeredi
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).