Skip to content

Commit f0c029d

Browse files
tobluxrostedt
authored andcommitted
tracing/osnoise: Replace kmalloc + copy_from_user with memdup_user_nul
Replace kmalloc() followed by copy_from_user() with memdup_user_nul() to simplify and improve osnoise_cpus_write(). Remove the manual NUL-termination. No functional changes intended. Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Link: https://lore.kernel.org/20251001130907.364673-2-thorsten.blum@linux.dev Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent e5f0a69 commit f0c029d

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

kernel/trace/trace_osnoise.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/sched/clock.h>
2525
#include <uapi/linux/sched/types.h>
2626
#include <linux/sched.h>
27+
#include <linux/string.h>
2728
#include "trace.h"
2829

2930
#ifdef CONFIG_X86_LOCAL_APIC
@@ -2325,13 +2326,9 @@ osnoise_cpus_write(struct file *filp, const char __user *ubuf, size_t count,
23252326
if (count < 1)
23262327
return 0;
23272328

2328-
buf = kmalloc(count + 1, GFP_KERNEL);
2329-
if (!buf)
2330-
return -ENOMEM;
2331-
2332-
if (copy_from_user(buf, ubuf, count))
2333-
return -EFAULT;
2334-
buf[count] = '\0';
2329+
buf = memdup_user_nul(ubuf, count);
2330+
if (IS_ERR(buf))
2331+
return PTR_ERR(buf);
23352332

23362333
if (!zalloc_cpumask_var(&osnoise_cpumask_new, GFP_KERNEL))
23372334
return -ENOMEM;

0 commit comments

Comments
 (0)