[RESEND PATCH] f2fs: Use struct_size() to improve f2fs_acl_clone()

Thorsten Blum posted 1 patch 1 month, 3 weeks ago
There is a newer version of this series
fs/f2fs/acl.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
[RESEND PATCH] f2fs: Use struct_size() to improve f2fs_acl_clone()
Posted by Thorsten Blum 1 month, 3 weeks ago
Use struct_size() to calculate the number of bytes to allocate for a
cloned acl.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 fs/f2fs/acl.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/acl.c b/fs/f2fs/acl.c
index 8bffdeccdbc3..1fbc0607363b 100644
--- a/fs/f2fs/acl.c
+++ b/fs/f2fs/acl.c
@@ -296,9 +296,8 @@ static struct posix_acl *f2fs_acl_clone(const struct posix_acl *acl,
 	struct posix_acl *clone = NULL;
 
 	if (acl) {
-		int size = sizeof(struct posix_acl) + acl->a_count *
-				sizeof(struct posix_acl_entry);
-		clone = kmemdup(acl, size, flags);
+		clone = kmemdup(acl, struct_size(acl, a_entries, acl->a_count),
+				flags);
 		if (clone)
 			refcount_set(&clone->a_refcount, 1);
 	}
-- 
2.46.2
Re: [RESEND PATCH] f2fs: Use struct_size() to improve f2fs_acl_clone()
Posted by Chao Yu 1 month, 2 weeks ago
On 2024/10/7 19:46, Thorsten Blum wrote:
> Use struct_size() to calculate the number of bytes to allocate for a
> cloned acl.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,