cifsd: fix memdup.cocci warnings
authorkernel test robot <lkp@intel.com>
Fri, 2 Apr 2021 03:17:24 +0000 (12:17 +0900)
committerSteve French <stfrench@microsoft.com>
Tue, 11 May 2021 00:15:36 +0000 (19:15 -0500)
fs/cifsd/smb2pdu.c:1177:27-34: WARNING opportunity for kmemdup

 Use kmemdup rather than duplicating its implementation

Generated by: scripts/coccinelle/api/memdup.cocci

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: kernel test robot <lkp@intel.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/cifsd/smb2pdu.c

index 7549b35bb7926142a6a1be768ca8b2b22b3e24b7..e6cdc3b89d85a84af7f0b47121b4258057046b0f 100644 (file)
@@ -1161,13 +1161,11 @@ static int alloc_preauth_hash(struct ksmbd_session *sess,
        if (sess->Preauth_HashValue)
                return 0;
 
-       sess->Preauth_HashValue = kmalloc(PREAUTH_HASHVALUE_SIZE, GFP_KERNEL);
+       sess->Preauth_HashValue = kmemdup(conn->preauth_info->Preauth_HashValue,
+                       PREAUTH_HASHVALUE_SIZE, GFP_KERNEL);
        if (!sess->Preauth_HashValue)
                return -ENOMEM;
 
-       memcpy(sess->Preauth_HashValue,
-              conn->preauth_info->Preauth_HashValue,
-              PREAUTH_HASHVALUE_SIZE);
        return 0;
 }