ksmbd: switch to use kmemdup_nul() helper
authorYang Yingliang <yangyingliang@huawei.com>
Tue, 25 Jul 2023 12:31:47 +0000 (20:31 +0800)
committerSteve French <stfrench@microsoft.com>
Tue, 29 Aug 2023 17:30:19 +0000 (12:30 -0500)
Use kmemdup_nul() helper instead of open-coding to
simplify the code.

Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/server/asn1.c

index cc6384f..4a4b2b0 100644 (file)
@@ -214,12 +214,10 @@ static int ksmbd_neg_token_alloc(void *context, size_t hdrlen,
 {
        struct ksmbd_conn *conn = context;
 
-       conn->mechToken = kmalloc(vlen + 1, GFP_KERNEL);
+       conn->mechToken = kmemdup_nul(value, vlen, GFP_KERNEL);
        if (!conn->mechToken)
                return -ENOMEM;
 
-       memcpy(conn->mechToken, value, vlen);
-       conn->mechToken[vlen] = '\0';
        return 0;
 }