mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Geliang Tang <geliangtang@gmail.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Kees Cook <keescook@chromium.org>
Cc: Geliang Tang <geliangtang@gmail.com>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH] powerpc/nvram: use memdup_user
Date: Sat, 29 Apr 2017 09:45:13 +0800	[thread overview]
Message-ID: <773c52d0170a3fff971d03fc1ea8411541c4ece7.1493380763.git.geliangtang@gmail.com> (raw)
In-Reply-To: <4db2a0ba17dc68d7bcfbd7d47b0eb22ad9a220c2.1493381463.git.geliangtang@gmail.com>

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

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
 arch/powerpc/kernel/nvram_64.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c
index eae61b0..496d639 100644
--- a/arch/powerpc/kernel/nvram_64.c
+++ b/arch/powerpc/kernel/nvram_64.c
@@ -792,21 +792,17 @@ static ssize_t dev_nvram_write(struct file *file, const char __user *buf,
 	count = min_t(size_t, count, size - *ppos);
 	count = min(count, PAGE_SIZE);
 
-	ret = -ENOMEM;
-	tmp = kmalloc(count, GFP_KERNEL);
-	if (!tmp)
-		goto out;
-
-	ret = -EFAULT;
-	if (copy_from_user(tmp, buf, count))
+	tmp = memdup_user(buf, count);
+	if (IS_ERR(tmp)) {
+		ret = PTR_ERR(tmp);
 		goto out;
+	}
 
 	ret = ppc_md.nvram_write(tmp, count, ppos);
 
-out:
 	kfree(tmp);
+out:
 	return ret;
-
 }
 
 static long dev_nvram_ioctl(struct file *file, unsigned int cmd,
-- 
2.9.3

  parent reply	other threads:[~2017-04-29  1:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-29  1:45 [PATCH] cciss: " Geliang Tang
2017-04-29  1:45 ` [PATCH] floppy: " Geliang Tang
2017-04-29  1:45 ` Geliang Tang [this message]
2017-06-28  0:08   ` [PATCH] powerpc/nvram: " Kees Cook
2017-04-29  1:45 ` [PATCH] powerpc/powernv: " Geliang Tang
2017-07-27 12:37   ` Michael Ellerman
2017-04-29  1:45 ` [PATCH] powerpc/pseries: use memdup_user_nul Geliang Tang
2017-07-27 12:37   ` Michael Ellerman
2017-04-29  1:45 ` [PATCH] pstore: use memdup_user Geliang Tang
2017-06-28  0:07   ` Kees Cook
2017-04-29  1:45 ` [PATCH] skd_main: " Geliang Tang
2017-04-29  1:45 ` [PATCH] staging: comedi: " Geliang Tang
2017-04-29  1:53   ` Joe Perches
2017-04-29  5:17     ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=773c52d0170a3fff971d03fc1ea8411541c4ece7.1493380763.git.geliangtang@gmail.com \
    --to=geliangtang@gmail.com \
    --cc=benh@kernel.crashing.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®