* [PATCH -next] KEYS: trusted: Switch to kmemdup_nul()
@ 2021-04-12 16:00 Wei Yongjun
0 siblings, 0 replies; only message in thread
From: Wei Yongjun @ 2021-04-12 16:00 UTC (permalink / raw)
To: weiyongjun1, James Bottomley, Jarkko Sakkinen, Mimi Zohar,
David Howells, James Morris, Serge E. Hallyn, Sumit Garg
Cc: linux-integrity, keyrings, linux-security-module,
kernel-janitors, Hulk Robot
Use kmemdup_nul() helper instead of open-coding to
simplify the code.
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
security/keys/trusted-keys/trusted_core.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trusted-keys/trusted_core.c
index ec3a066a4b42..9430cba1f084 100644
--- a/security/keys/trusted-keys/trusted_core.c
+++ b/security/keys/trusted-keys/trusted_core.c
@@ -146,11 +146,9 @@ static int trusted_instantiate(struct key *key,
if (datalen <= 0 || datalen > 32767 || !prep->data)
return -EINVAL;
- datablob = kmalloc(datalen + 1, GFP_KERNEL);
+ datablob = kmemdup_nul(prep->data, datalen, GFP_KERNEL);
if (!datablob)
return -ENOMEM;
- memcpy(datablob, prep->data, datalen);
- datablob[datalen] = '\0';
payload = trusted_payload_alloc(key);
if (!payload) {
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-04-12 15:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12 16:00 [PATCH -next] KEYS: trusted: Switch to kmemdup_nul() Wei Yongjun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).