Skip to contentSkip to conversation

ovl: Replace offsetof() with struct_size() in ovl_cache_entry_new()

PATCH New Thorsten Blum 1 participant 1 message May 3, 2025 Overlay filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 fs/overlayfs/readdir.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/overlayfs/readdir.c +1 -2
index 881ec5592da5..1ae4a488af92 100644
@@ -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;
 
Signature · 1 line
2.49.0