f2fs: Use struct_size() to improve f2fs_acl_clone()
authorThorsten Blum <thorsten.blum@linux.dev>
Mon, 7 Oct 2024 11:46:37 +0000 (13:46 +0200)
committerJaegeuk Kim <jaegeuk@kernel.org>
Mon, 14 Oct 2024 20:04:57 +0000 (20:04 +0000)
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>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/acl.c

index 8bffdec..1fbc060 100644 (file)
@@ -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);
        }