linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next 1/3] fail_function: Switch to memdup_user_nul() helper
@ 2022-08-26  7:33 Yang Yingliang
  2022-08-26  7:33 ` [PATCH -next 2/3] fail_function: refctor code of checking return value of register_kprobe() Yang Yingliang
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Yang Yingliang @ 2022-08-26  7:33 UTC (permalink / raw)
  To: linux-kernel; +Cc: mhiramat, ast, jbacik, akpm

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

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 kernel/fail_function.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/kernel/fail_function.c b/kernel/fail_function.c
index 60dc825ecc2b..03643e33e4c3 100644
--- a/kernel/fail_function.c
+++ b/kernel/fail_function.c
@@ -247,15 +247,11 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
 	/* cut off if it is too long */
 	if (count > KSYM_NAME_LEN)
 		count = KSYM_NAME_LEN;
-	buf = kmalloc(count + 1, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
 
-	if (copy_from_user(buf, buffer, count)) {
-		ret = -EFAULT;
-		goto out_free;
-	}
-	buf[count] = '\0';
+	buf = memdup_user_nul(buffer, count);
+	if (IS_ERR(buf))
+		return PTR_ERR(buf);
+
 	sym = strstrip(buf);
 
 	mutex_lock(&fei_lock);
@@ -308,7 +304,6 @@ static ssize_t fei_write(struct file *file, const char __user *buffer,
 	}
 out:
 	mutex_unlock(&fei_lock);
-out_free:
 	kfree(buf);
 	return ret;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-12  9:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-26  7:33 [PATCH -next 1/3] fail_function: Switch to memdup_user_nul() helper Yang Yingliang
2022-08-26  7:33 ` [PATCH -next 2/3] fail_function: refctor code of checking return value of register_kprobe() Yang Yingliang
2022-09-12  9:37   ` Masami Hiramatsu
2022-08-26  7:33 ` [PATCH -next 3/3] fail_function: fix wrong use of fei_attr_remove() Yang Yingliang
2022-09-12  9:37 ` [PATCH -next 1/3] fail_function: Switch to memdup_user_nul() helper Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).