Re: [PATCH RESEND 1/2] stm class: Replace kmalloc + copy_from_user with memdup_user
From: Thorsten Blum <thorsten.blum@linux.dev>
Date: 2026-05-25 09:37:12
Also in:
lkml
From: Thorsten Blum <thorsten.blum@linux.dev>
Date: 2026-05-25 09:37:12
Also in:
lkml
Gentle ping? On Thu, Apr 02, 2026 at 06:59:35PM +0200, Thorsten Blum wrote:
Replace kmalloc() followed by copy_from_user() with memdup_user() to simplify and improve stm_char_write(). Allocate and copy only 'count' bytes instead of 'count + 1' since the extra byte is unused. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> --- drivers/hwtracing/stm/core.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c index 37584e786bb5..49791024bb86 100644 --- a/drivers/hwtracing/stm/core.c +++ b/drivers/hwtracing/stm/core.c@@ -645,15 +645,9 @@ static ssize_t stm_char_write(struct file *file, const char __user *buf, return err; } - kbuf = kmalloc(count + 1, GFP_KERNEL); - if (!kbuf) - return -ENOMEM; - - err = copy_from_user(kbuf, buf, count); - if (err) { - kfree(kbuf); - return -EFAULT; - } + kbuf = memdup_user(buf, count); + if (IS_ERR(kbuf)) + return PTR_ERR(kbuf); pm_runtime_get_sync(&stm->dev);