aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSilviu-Mihai Popescu <silviupopescu1990@gmail.com>2013-03-11 12:22:32 -0400
committerSteve French <smfrench@gmail.com>2013-05-04 23:08:19 -0400
commitf7f7c1850eb98da758731ea7edfa830ebefe24cd (patch)
tree78e8199747533ec4b78e27fd739ea68ebf13a171
parentd455b72bdd23a1d7adcbdfb5c1ceabcd7beaf853 (diff)
fs: cifs: use kmemdup instead of kmalloc + memcpy
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>
-rw-r--r--fs/cifs/cifs_spnego.c3
-rw-r--r--fs/cifs/cifsacl.c3
-rw-r--r--fs/cifs/cifssmb.c3
-rw-r--r--fs/cifs/sess.c8
4 files changed, 7 insertions, 10 deletions
diff --git a/fs/cifs/cifs_spnego.c b/fs/cifs/cifs_spnego.c
index 10e774761299..b7ae3cb55549 100644
--- a/fs/cifs/cifs_spnego.c
+++ b/fs/cifs/cifs_spnego.c
@@ -37,12 +37,11 @@ cifs_spnego_key_instantiate(struct key *key, struct key_preparsed_payload *prep)
37 int ret; 37 int ret;
38 38
39 ret = -ENOMEM; 39 ret = -ENOMEM;
40 payload = kmalloc(prep->datalen, GFP_KERNEL); 40 payload = kmemdup(prep->data, prep->datalen, GFP_KERNEL);
41 if (!payload) 41 if (!payload)
42 goto error; 42 goto error;
43 43
44 /* attach the data */ 44 /* attach the data */
45 memcpy(payload, prep->data, prep->datalen);
46 key->payload.data = payload; 45 key->payload.data = payload;
47 ret = 0; 46 ret = 0;
48 47
diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c
index f1e3f25fe004..0bba930d0009 100644
--- a/fs/cifs/cifsacl.c
+++ b/fs/cifs/cifsacl.c
@@ -63,11 +63,10 @@ cifs_idmap_key_instantiate(struct key *key, struct key_preparsed_payload *prep)
63 key->datalen = prep->datalen; 63 key->datalen = prep->datalen;
64 return 0; 64 return 0;
65 } 65 }
66 payload = kmalloc(prep->datalen, GFP_KERNEL); 66 payload = kmemdup(prep->data, prep->datalen, GFP_KERNEL);
67 if (!payload) 67 if (!payload)
68 return -ENOMEM; 68 return -ENOMEM;
69 69
70 memcpy(payload, prep->data, prep->datalen);
71 key->payload.data = payload; 70 key->payload.data = payload;
72 key->datalen = prep->datalen; 71 key->datalen = prep->datalen;
73 return 0; 72 return 0;
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 8e2e799e7a24..1e7a4fe1f810 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -3742,12 +3742,11 @@ CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid,
3742 rc = -EINVAL; 3742 rc = -EINVAL;
3743 *pbuflen = 0; 3743 *pbuflen = 0;
3744 } else { 3744 } else {
3745 *acl_inf = kmalloc(*pbuflen, GFP_KERNEL); 3745 *acl_inf = kmemdup(pdata, *pbuflen, GFP_KERNEL);
3746 if (*acl_inf == NULL) { 3746 if (*acl_inf == NULL) {
3747 *pbuflen = 0; 3747 *pbuflen = 0;
3748 rc = -ENOMEM; 3748 rc = -ENOMEM;
3749 } 3749 }
3750 memcpy(*acl_inf, pdata, *pbuflen);
3751 } 3750 }
3752 } 3751 }
3753qsec_out: 3752qsec_out:
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
index 76809f4d3428..6f83881ff30b 100644
--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -399,12 +399,12 @@ int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
399 return -EINVAL; 399 return -EINVAL;
400 } 400 }
401 if (tilen) { 401 if (tilen) {
402 ses->auth_key.response = kmalloc(tilen, GFP_KERNEL); 402 ses->auth_key.response = kmemdup(bcc_ptr + tioffset, tilen,
403 GFP_KERNEL);
403 if (!ses->auth_key.response) { 404 if (!ses->auth_key.response) {
404 cERROR(1, "Challenge target info allocation failure"); 405 cERROR(1, "Challenge target info allocation failure");
405 return -ENOMEM; 406 return -ENOMEM;
406 } 407 }
407 memcpy(ses->auth_key.response, bcc_ptr + tioffset, tilen);
408 ses->auth_key.len = tilen; 408 ses->auth_key.len = tilen;
409 } 409 }
410 410
@@ -761,14 +761,14 @@ ssetup_ntlmssp_authenticate:
761 goto ssetup_exit; 761 goto ssetup_exit;
762 } 762 }
763 763
764 ses->auth_key.response = kmalloc(msg->sesskey_len, GFP_KERNEL); 764 ses->auth_key.response = kmemdup(msg->data, msg->sesskey_len,
765 GFP_KERNEL);
765 if (!ses->auth_key.response) { 766 if (!ses->auth_key.response) {
766 cERROR(1, "Kerberos can't allocate (%u bytes) memory", 767 cERROR(1, "Kerberos can't allocate (%u bytes) memory",
767 msg->sesskey_len); 768 msg->sesskey_len);
768 rc = -ENOMEM; 769 rc = -ENOMEM;
769 goto ssetup_exit; 770 goto ssetup_exit;
770 } 771 }
771 memcpy(ses->auth_key.response, msg->data, msg->sesskey_len);
772 ses->auth_key.len = msg->sesskey_len; 772 ses->auth_key.len = msg->sesskey_len;
773 773
774 pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC; 774 pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;