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


Groups > linux.kernel > #1468478

[PATCH] staging: i4l: icn: use memdup_user

From Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Newsgroups linux.kernel
Subject [PATCH] staging: i4l: icn: use memdup_user
Date 2016-08-23 12:50 +0200
Message-ID <s9hrj-2PE-7@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


Its better to use memdup_user which does the same thing which this
code has implemented.

Suggested-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
---
 drivers/staging/i4l/icn/icn.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/i4l/icn/icn.c b/drivers/staging/i4l/icn/icn.c
index b2f4055..5312675 100644
--- a/drivers/staging/i4l/icn/icn.c
+++ b/drivers/staging/i4l/icn/icn.c
@@ -804,21 +804,16 @@ static int
 icn_loadboot(u_char __user *buffer, icn_card *card)
 {
 	int ret;
-	u_char *codebuf;
+	void *codebuf;
 	unsigned long flags;
 
 #ifdef BOOT_DEBUG
 	printk(KERN_DEBUG "icn_loadboot called, buffaddr=%08lx\n", (ulong) buffer);
 #endif
-	codebuf = kmalloc(ICN_CODE_STAGE1, GFP_KERNEL);
-	if (!codebuf) {
-		printk(KERN_WARNING "icn: Could not allocate code buffer\n");
-		ret = -ENOMEM;
-		goto out;
-	}
-	if (copy_from_user(codebuf, buffer, ICN_CODE_STAGE1)) {
-		ret = -EFAULT;
-		goto out_kfree;
+	codebuf = memdup_user(buffer, ICN_CODE_STAGE1);
+	if (IS_ERR(codebuf)) {
+		pr_warn("icn: Could not allocate code buffer\n");
+		return PTR_ERR(codebuf);
 	}
 	if (!card->rvalid) {
 		if (!request_region(card->port, ICN_PORTLEN, card->regname)) {
@@ -902,7 +897,6 @@ icn_loadboot(u_char __user *buffer, icn_card *card)
 
 out_kfree:
 	kfree(codebuf);
-out:
 	return ret;
 }
 
-- 
1.9.1

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] staging: i4l: icn: use memdup_user Sudip Mukherjee <sudipm.mukherjee@gmail.com> - 2016-08-23 12:50 +0200
  Re: [PATCH] staging: i4l: icn: use memdup_user Sudip Mukherjee <sudipm.mukherjee@gmail.com> - 2016-08-23 13:00 +0200
    Re: [PATCH] staging: i4l: icn: use memdup_user Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-08-23 15:10 +0200
  Re: [PATCH] staging: i4l: icn: use memdup_user Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-08-23 13:00 +0200

csiph-web