Skip to contentSkip to conversation

KEYS: trusted: Switch to kmemdup_nul()

PATCH In review Yang Yingliang 2 participants 2 messages Apr 2, 2021 – Apr 4, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KEYS: trusted: Switch to kmemdup_nul()

Use kmemdup_nul() helper instead of open-coding to simplify the code.

---
 security/keys/trusted-keys/trusted_tpm1.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
security/keys/trusted-keys/trusted_tpm1.c +1 -3
index 493eb91ed017..90ded4757e79 100644
@@ -978,11 +978,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';
 
 	options = trusted_options_alloc();
 	if (!options) {
Signature · 1 line
2.25.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Yang Yingliang

Use kmemdup_nul() helper instead of open-coding to simplify the code.

---
 security/keys/trusted-keys/trusted_tpm1.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

/Jarkko

Quoted 22 lines
security/keys/trusted-keys/trusted_tpm1.c +1 -3
index 493eb91ed017..90ded4757e79 100644
@@ -978,11 +978,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';
 
 	options = trusted_options_alloc();
 	if (!options) {
Signature · 1 line
2.25.1