Skip to content

Commit 6434e3e

Browse files
tracing/osnoise: Replace kmalloc + copy_from_user with memdup_user_nul
JIRA: https://issues.redhat.com/browse/RHEL-117873 commit f0c029d Author: Thorsten Blum <thorsten.blum@linux.dev> Date: Wed Oct 1 15:09:07 2025 +0200 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> Signed-off-by: Tomas Glozar <tglozar@redhat.com>
1 parent bb770c5 commit 6434e3e

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
@@ -2331,13 +2332,9 @@ osnoise_cpus_write(struct file *filp, const char __user *ubuf, size_t count,
23312332
if (count < 1)
23322333
return 0;
23332334

2334-
buf = kmalloc(count + 1, GFP_KERNEL);
2335-
if (!buf)
2336-
return -ENOMEM;
2337-
2338-
if (copy_from_user(buf, ubuf, count))
2339-
return -EFAULT;
2340-
buf[count] = '\0';
2335+
buf = memdup_user_nul(ubuf, count);
2336+
if (IS_ERR(buf))
2337+
return PTR_ERR(buf);
23412338

23422339
if (!zalloc_cpumask_var(&osnoise_cpumask_new, GFP_KERNEL))
23432340
return -ENOMEM;

0 commit comments

Comments
 (0)