[PATCH RESEND 2/2] stm class: Replace kzalloc + copy_from_user with memdup_user_nul

From: Thorsten Blum

Date: Tue Jan 27 2026 - 06:07:34 EST


Replace kzalloc() followed by copy_from_user() with memdup_user_nul() to
simplify and improve stm_char_policy_set_ioctl(). Remove the obsolete
comment.

Signed-off-by: Thorsten Blum <thorsten.blum@xxxxxxxxx>
---
drivers/hwtracing/stm/core.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
index 5834f796e86b..335bcf749214 100644
--- a/drivers/hwtracing/stm/core.c
+++ b/drivers/hwtracing/stm/core.c
@@ -733,18 +733,9 @@ static int stm_char_policy_set_ioctl(struct stm_file *stmf, void __user *arg)
if (size < sizeof(*id) || size >= PATH_MAX + sizeof(*id))
return -EINVAL;

- /*
- * size + 1 to make sure the .id string at the bottom is terminated,
- * which is also why memdup_user() is not useful here
- */
- id = kzalloc(size + 1, GFP_KERNEL);
- if (!id)
- return -ENOMEM;
-
- if (copy_from_user(id, arg, size)) {
- ret = -EFAULT;
- goto err_free;
- }
+ id = memdup_user_nul(arg, size);
+ if (IS_ERR(id))
+ return PTR_ERR(id);

if (id->__reserved_0 || id->__reserved_1)
goto err_free;
--
Thorsten Blum <thorsten.blum@xxxxxxxxx>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4