fs: cifs: use kmemdup instead of kmalloc + memcpy
authorSilviu-Mihai Popescu <silviupopescu1990@gmail.com>
Mon, 11 Mar 2013 16:22:32 +0000 (18:22 +0200)
committerSteve French <smfrench@gmail.com>
Sun, 5 May 2013 03:08:19 +0000 (22:08 -0500)
This replaces calls to kmalloc followed by memcpy with a single call to
kmemdup. This was found via make coccicheck.

Signed-off-by: Silviu-Mihai Popescu <silviupopescu1990@gmail.com>
Signed-off-by: Steve French <sfrench@us.ibm.com>
Signed-off-by: Steve French <smfrench@gmail.com>
fs/cifs/cifs_spnego.c
fs/cifs/cifsacl.c
fs/cifs/cifssmb.c
fs/cifs/sess.c

index 10e7747612992bcc25706851c9027762e2fc134d..b7ae3cb55549f902f7b225b42dc14b7f2ca5c0d3 100644 (file)
@@ -37,12 +37,11 @@ cifs_spnego_key_instantiate(struct key *key, struct key_preparsed_payload *prep)
        int ret;
 
        ret = -ENOMEM;
-       payload = kmalloc(prep->datalen, GFP_KERNEL);
+       payload = kmemdup(prep->data, prep->datalen, GFP_KERNEL);
        if (!payload)
                goto error;
 
        /* attach the data */
-       memcpy(payload, prep->data, prep->datalen);
        key->payload.data = payload;
        ret = 0;
 
index f1e3f25fe00412a584a70883a5cf6f661741d821..0bba930d000936b0756410a5281bcf24e54d07ca 100644 (file)
@@ -63,11 +63,10 @@ cifs_idmap_key_instantiate(struct key *key, struct key_preparsed_payload *prep)
                key->datalen = prep->datalen;
                return 0;
        }
-       payload = kmalloc(prep->datalen, GFP_KERNEL);
+       payload = kmemdup(prep->data, prep->datalen, GFP_KERNEL);
        if (!payload)
                return -ENOMEM;
 
-       memcpy(payload, prep->data, prep->datalen);
        key->payload.data = payload;
        key->datalen = prep->datalen;
        return 0;
index 8e2e799e7a2451e5dd7300a57fbf81b32a28bf94..1e7a4fe1f810faf58c19d98d7fdf1bf12bffa83d 100644 (file)
@@ -3742,12 +3742,11 @@ CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid,
                        rc = -EINVAL;
                        *pbuflen = 0;
                } else {
-                       *acl_inf = kmalloc(*pbuflen, GFP_KERNEL);
+                       *acl_inf = kmemdup(pdata, *pbuflen, GFP_KERNEL);
                        if (*acl_inf == NULL) {
                                *pbuflen = 0;
                                rc = -ENOMEM;
                        }
-                       memcpy(*acl_inf, pdata, *pbuflen);
                }
        }
 qsec_out:
index 76809f4d34284420934d85374c09a5093a5d75f3..6f83881ff30b9d9c4e38b8f00f10d44e627cb5bb 100644 (file)
@@ -399,12 +399,12 @@ int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
                return -EINVAL;
        }
        if (tilen) {
-               ses->auth_key.response = kmalloc(tilen, GFP_KERNEL);
+               ses->auth_key.response = kmemdup(bcc_ptr + tioffset, tilen,
+                                                GFP_KERNEL);
                if (!ses->auth_key.response) {
                        cERROR(1, "Challenge target info allocation failure");
                        return -ENOMEM;
                }
-               memcpy(ses->auth_key.response, bcc_ptr + tioffset, tilen);
                ses->auth_key.len = tilen;
        }
 
@@ -761,14 +761,14 @@ ssetup_ntlmssp_authenticate:
                        goto ssetup_exit;
                }
 
-               ses->auth_key.response = kmalloc(msg->sesskey_len, GFP_KERNEL);
+               ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len,
+                                                GFP_KERNEL);
                if (!ses->auth_key.response) {
                        cERROR(1, "Kerberos can't allocate (%u bytes) memory",
                                        msg->sesskey_len);
                        rc = -ENOMEM;
                        goto ssetup_exit;
                }
-               memcpy(ses->auth_key.response, msg->data, msg->sesskey_len);
                ses->auth_key.len = msg->sesskey_len;
 
                pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;