]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ksmbd: ipc: use kzalloc_flex and __counted_by
authorRosen Penev <rosenp@gmail.com>
Fri, 6 Mar 2026 06:35:22 +0000 (22:35 -0800)
committerSteve French <stfrench@microsoft.com>
Sun, 12 Apr 2026 23:07:54 +0000 (18:07 -0500)
The former is just a nice macro and the latter allows runtime analysis
of the allocation and its size.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/server/transport_ipc.c

index 2dbabe2d8005541b2b7457c531b564b4f98f97fd..f7aa427a06fe2cc21df9e760c1ec85d60ac2c1eb 100644 (file)
@@ -55,7 +55,7 @@ static bool ksmbd_ipc_validate_version(struct genl_info *m)
 struct ksmbd_ipc_msg {
        unsigned int            type;
        unsigned int            sz;
-       unsigned char           payload[];
+       unsigned char           payload[] __counted_by(sz);
 };
 
 struct ipc_msg_table_entry {
@@ -242,9 +242,8 @@ static void ipc_update_last_active(void)
 static struct ksmbd_ipc_msg *ipc_msg_alloc(size_t sz)
 {
        struct ksmbd_ipc_msg *msg;
-       size_t msg_sz = sz + sizeof(struct ksmbd_ipc_msg);
 
-       msg = kvzalloc(msg_sz, KSMBD_DEFAULT_GFP);
+       msg = kvzalloc_flex(*msg, payload, sz, KSMBD_DEFAULT_GFP);
        if (msg)
                msg->sz = sz;
        return msg;