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


Groups > linux.kernel > #1468581 > unrolled thread

[PATCH v2] staging: i4l: icn: use memdup_user

Started bySudip Mukherjee <sudipm.mukherjee@gmail.com>
First post2016-08-23 16:20 +0200
Last post2016-08-23 16:20 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH v2] staging: i4l: icn: use memdup_user Sudip Mukherjee <sudipm.mukherjee@gmail.com> - 2016-08-23 16:20 +0200

#1468581 — [PATCH v2] staging: i4l: icn: use memdup_user

FromSudip Mukherjee <sudipm.mukherjee@gmail.com>
Date2016-08-23 16:20 +0200
Subject[PATCH v2] staging: i4l: icn: use memdup_user
Message-ID<s9kIx-563-19@gated-at.bofh.it>
Its better to use memdup_user which does the same thing which this
code has implemented. Also removed a related warning as we will be
warned if allocation fails.

Suggested-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
---

v2: removed type change done in v1, and removed a warning.

 drivers/staging/i4l/icn/icn.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/i4l/icn/icn.c b/drivers/staging/i4l/icn/icn.c
index b2f4055..415124f 100644
--- a/drivers/staging/i4l/icn/icn.c
+++ b/drivers/staging/i4l/icn/icn.c
@@ -810,16 +810,10 @@ icn_loadboot(u_char __user *buffer, icn_card *card)
 #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))
+		return PTR_ERR(codebuf);
+
 	if (!card->rvalid) {
 		if (!request_region(card->port, ICN_PORTLEN, card->regname)) {
 			printk(KERN_WARNING
@@ -902,7 +896,6 @@ icn_loadboot(u_char __user *buffer, icn_card *card)
 
 out_kfree:
 	kfree(codebuf);
-out:
 	return ret;
 }
 
-- 
1.9.1

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web