sysfs: use memdup_user()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Tuesday, April 21, 2009 - 2:59 pm

Gitweb:     http://git.kernel.org/linus/1c8542c7bb239ef02fe21477acd9cdac04c1b640
Commit:     1c8542c7bb239ef02fe21477acd9cdac04c1b640
Parent:     dae7b665cf6d6e6e733f1c9c16cf55547dd37e33
Author:     Li Zefan <lizf@cn.fujitsu.com>
AuthorDate: Wed Apr 8 15:07:30 2009 +0800
Committer:  Al Viro <viro@zeniv.linux.org.uk>
CommitDate: Mon Apr 20 23:02:50 2009 -0400

    sysfs: use memdup_user()
    
    Remove open-coded memdup_user().
    
    Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
    Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/sysfs/bin.c |   13 +++----------
 1 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
index 93e0c02..9345806 100644
--- a/fs/sysfs/bin.c
+++ b/fs/sysfs/bin.c
@@ -157,14 +157,9 @@ static ssize_t write(struct file *file, const char __user *userbuf,
 			count = size - offs;
 	}
 
-	temp = kmalloc(count, GFP_KERNEL);
-	if (!temp)
-		return -ENOMEM;
-
-	if (copy_from_user(temp, userbuf, count)) {
-		count = -EFAULT;
-		goto out_free;
-	}
+	temp = memdup_user(userbuf, count);
+	if (IS_ERR(temp))
+		return PTR_ERR(temp);
 
 	mutex_lock(&bb->mutex);
 
@@ -176,8 +171,6 @@ static ssize_t write(struct file *file, const char __user *userbuf,
 	if (count > 0)
 		*off = offs + count;
 
-out_free:
-	kfree(temp);
 	return count;
 }
 
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
sysfs: use memdup_user(), Linux Kernel Mailing ..., (Tue Apr 21, 2:59 pm)