[PATCH 12/17] s390/debug: Use memdup_user() rather than duplicating its implementation

SF Markus Elfring
2016-09-03T12:30:23Z

Date: Fri, 2 Sep 2016 08:45:26 +0200

Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
arch/s390/kernel/debug.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/arch/s390/kernel/debug.c b/arch/s390/kernel/debug.c
index 4a12faf..a9fcf72 100644
--- a/arch/s390/kernel/debug.c
+++ b/arch/s390/kernel/debug.c
@@ -1162,13 +1162,9 @@ debug_get_user_string(const char __user *user_buf, size_t user_len)
{
char* buffer;

- buffer = kmalloc(user_len + 1, GFP_KERNEL);
- if (!buffer)
- return ERR_PTR(-ENOMEM);
- if (copy_from_user(buffer, user_buf, user_len) != 0) {
- kfree(buffer);
- return ERR_PTR(-EFAULT);
- }
+ buffer = memdup_user(user_buf, user_len + 1);
+ if (IS_ERR(buffer))
+ return PTR_ERR(buffer);
/* got the string, now strip linefeed. */
if (buffer[user_len - 1] == '\n')
buffer[user_len - 1] = 0;
--
2.9.3