Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1656222 > unrolled thread

[PATCH 11/13] efi/efi_test: Use memdup_user() helper

Started byArd Biesheuvel <ard.biesheuvel@linaro.org>
First post2017-06-02 16:00 +0200
Last post2017-06-05 19:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 11/13] efi/efi_test: Use memdup_user() helper Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2017-06-02 16:00 +0200
    [tip:efi/core] efi/efi_test: Use memdup_user() helper tip-bot for Geliang Tang <tipbot@zytor.com> - 2017-06-05 19:30 +0200

#1656222 — [PATCH 11/13] efi/efi_test: Use memdup_user() helper

FromArd Biesheuvel <ard.biesheuvel@linaro.org>
Date2017-06-02 16:00 +0200
Subject[PATCH 11/13] efi/efi_test: Use memdup_user() helper
Message-ID<tNVho-1Vg-17@gated-at.bofh.it>
From: Geliang Tang <geliangtang@gmail.com>

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

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
Acked-by: Ivan Hu <ivan.hu@canonical.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 drivers/firmware/efi/test/efi_test.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/firmware/efi/test/efi_test.c b/drivers/firmware/efi/test/efi_test.c
index 8cd578f62059..08129b7b80ab 100644
--- a/drivers/firmware/efi/test/efi_test.c
+++ b/drivers/firmware/efi/test/efi_test.c
@@ -71,18 +71,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.9.3

[toc] | [next] | [standalone]


#1658025 — [tip:efi/core] efi/efi_test: Use memdup_user() helper

Fromtip-bot for Geliang Tang <tipbot@zytor.com>
Date2017-06-05 19:30 +0200
Subject[tip:efi/core] efi/efi_test: Use memdup_user() helper
Message-ID<tP3Zi-5PM-63@gated-at.bofh.it>
In reply to#1656222
Commit-ID:  5f72cad65cfaac5e40d0de8b7f48ee647af69cd5
Gitweb:     http://git.kernel.org/tip/5f72cad65cfaac5e40d0de8b7f48ee647af69cd5
Author:     Geliang Tang <geliangtang@gmail.com>
AuthorDate: Fri, 2 Jun 2017 13:52:05 +0000
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 5 Jun 2017 17:50:42 +0200

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@gmail.com>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Ivan Hu <ivan.hu@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/20170602135207.21708-12-ard.biesheuvel@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 drivers/firmware/efi/test/efi_test.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/firmware/efi/test/efi_test.c b/drivers/firmware/efi/test/efi_test.c
index 8cd578f..08129b7 100644
--- a/drivers/firmware/efi/test/efi_test.c
+++ b/drivers/firmware/efi/test/efi_test.c
@@ -71,18 +71,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;
 }
 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web