Skip to contentSkip to conversation

KEYS: trusted: Switch to kmemdup_nul()

PATCH New Wei Yongjun 1 participant 1 message Apr 12, 2021

Subsystems (4)
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_core.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
security/keys/trusted-keys/trusted_core.c +1 -3
index ec3a066a4b42..9430cba1f084 100644
@@ -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) {