[PATCH] efi_runtime: Use memdup_user helper

Ivan Hu ivan.hu at canonical.com
Mon Jul 3 07:48:56 UTC 2017


From: Geliang Tang <geliangtang at gmail.com>

Sync up with kernel driver efi_test:

efi/efi_test: Use memdup_user() helper

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

Signed-off-by: Geliang Tang <geliangtang at gmail.com>
Signed-off-by: Ivan Hu <ivan.hu at canonical.com>
---
 efi_runtime/efi_runtime.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/efi_runtime/efi_runtime.c b/efi_runtime/efi_runtime.c
index 19b624c..6570a54 100644
--- a/efi_runtime/efi_runtime.c
+++ b/efi_runtime/efi_runtime.c
@@ -90,18 +90,13 @@ copy_ucs2_from_user_len(efi_char16_t **dst, efi_char16_t __user *src,
 	if (!access_ok(VERIFY_READ, src, 1))
 		return -EFAULT;
 
-	buf = kmalloc(len, GFP_KERNEL);
-	if (!buf) {
+	buf = memdup_user(src, len);
+	if (IS_ERR(buf)) {
 		*dst = NULL;
-		return -ENOMEM;
+		return PTR_ERR(buf);
 	}
 	*dst = buf;
 
-	if (copy_from_user(*dst, src, len)) {
-		kfree(buf);
-		return -EFAULT;
-	}
-
 	return 0;
 }
 
-- 
2.7.4




More information about the fwts-devel mailing list