Skip to contentSkip to conversation

tracing/osnoise: Replace kmalloc() + copy_from_user() with memdup_user()

PATCH Superseded Thorsten Blum 1 participant 1 message Sep 5, 2025

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing/osnoise: Replace kmalloc() + copy_from_user() with memdup_user()

Replace kmalloc() followed by copy_from_user() with memdup_user() to improve and simplify osnoise_cpus_write().

No functional changes intended.

---
 kernel/trace/trace_osnoise.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
kernel/trace/trace_osnoise.c +3 -6
index fd259da0aa64..dd97f6bd03a4 100644
@@ -2322,12 +2322,9 @@ osnoise_cpus_write(struct file *filp, const char __user *ubuf, size_t count,
 	int running, err;
 	char *buf __free(kfree) = NULL;
 
-	buf = kmalloc(count, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-
-	if (copy_from_user(buf, ubuf, count))
-		return -EFAULT;
+	buf = memdup_user(ubuf, count);
+	if (IS_ERR(buf))
+		return PTR_ERR(buf);
 
 	if (!zalloc_cpumask_var(&osnoise_cpumask_new, GFP_KERNEL))
 		return -ENOMEM;
Signature · 1 line
2.51.0