Commit f7f7c185 authored by Silviu-Mihai Popescu's avatar Silviu-Mihai Popescu Committed by Steve French

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: default avatarSilviu-Mihai Popescu <silviupopescu1990@gmail.com>
Signed-off-by: default avatarSteve French <sfrench@us.ibm.com>
Signed-off-by: default avatarSteve French <smfrench@gmail.com>
parent d455b72b
...@@ -37,12 +37,11 @@ cifs_spnego_key_instantiate(struct key *key, struct key_preparsed_payload *prep) ...@@ -37,12 +37,11 @@ cifs_spnego_key_instantiate(struct key *key, struct key_preparsed_payload *prep)
int ret; int ret;
ret = -ENOMEM; ret = -ENOMEM;
payload = kmalloc(prep->datalen, GFP_KERNEL); payload = kmemdup(prep->data, prep->datalen, GFP_KERNEL);
if (!payload) if (!payload)
goto error; goto error;
/* attach the data */ /* attach the data */
memcpy(payload, prep->data, prep->datalen);
key->payload.data = payload; key->payload.data = payload;
ret = 0; ret = 0;
......
...@@ -63,11 +63,10 @@ cifs_idmap_key_instantiate(struct key *key, struct key_preparsed_payload *prep) ...@@ -63,11 +63,10 @@ cifs_idmap_key_instantiate(struct key *key, struct key_preparsed_payload *prep)
key->datalen = prep->datalen; key->datalen = prep->datalen;
return 0; return 0;
} }
payload = kmalloc(prep->datalen, GFP_KERNEL); payload = kmemdup(prep->data, prep->datalen, GFP_KERNEL);
if (!payload) if (!payload)
return -ENOMEM; return -ENOMEM;
memcpy(payload, prep->data, prep->datalen);
key->payload.data = payload; key->payload.data = payload;
key->datalen = prep->datalen; key->datalen = prep->datalen;
return 0; return 0;
......
...@@ -3742,12 +3742,11 @@ CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, ...@@ -3742,12 +3742,11 @@ CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid,
rc = -EINVAL; rc = -EINVAL;
*pbuflen = 0; *pbuflen = 0;
} else { } else {
*acl_inf = kmalloc(*pbuflen, GFP_KERNEL); *acl_inf = kmemdup(pdata, *pbuflen, GFP_KERNEL);
if (*acl_inf == NULL) { if (*acl_inf == NULL) {
*pbuflen = 0; *pbuflen = 0;
rc = -ENOMEM; rc = -ENOMEM;
} }
memcpy(*acl_inf, pdata, *pbuflen);
} }
} }
qsec_out: qsec_out:
......
...@@ -399,12 +399,12 @@ int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, ...@@ -399,12 +399,12 @@ int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
return -EINVAL; return -EINVAL;
} }
if (tilen) { 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) { if (!ses->auth_key.response) {
cERROR(1, "Challenge target info allocation failure"); cERROR(1, "Challenge target info allocation failure");
return -ENOMEM; return -ENOMEM;
} }
memcpy(ses->auth_key.response, bcc_ptr + tioffset, tilen);
ses->auth_key.len = tilen; ses->auth_key.len = tilen;
} }
...@@ -761,14 +761,14 @@ CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses, ...@@ -761,14 +761,14 @@ CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses,
goto ssetup_exit; 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) { if (!ses->auth_key.response) {
cERROR(1, "Kerberos can't allocate (%u bytes) memory", cERROR(1, "Kerberos can't allocate (%u bytes) memory",
msg->sesskey_len); msg->sesskey_len);
rc = -ENOMEM; rc = -ENOMEM;
goto ssetup_exit; goto ssetup_exit;
} }
memcpy(ses->auth_key.response, msg->data, msg->sesskey_len);
ses->auth_key.len = msg->sesskey_len; ses->auth_key.len = msg->sesskey_len;
pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC; pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment