From: Thorsten Blum <thorsten.blum@linux.dev>
To: Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH RESEND 2/2] stm class: Replace kzalloc + copy_from_user with memdup_user_nul
Date: Fri, 14 Nov 2025 17:04:15 +0100 [thread overview]
Message-ID: <20251114160416.230513-2-thorsten.blum@linux.dev> (raw)
In-Reply-To: <20251114160416.230513-1-thorsten.blum@linux.dev>
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@linux.dev>
---
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;
--
2.51.1
next prev parent reply other threads:[~2025-11-14 16:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 16:04 [PATCH RESEND 1/2] stm class: Replace kmalloc + copy_from_user with memdup_user Thorsten Blum
2025-11-14 16:04 ` Thorsten Blum [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-10-17 10:27 Thorsten Blum
2025-10-17 10:27 ` [PATCH RESEND 2/2] stm class: Replace kzalloc + copy_from_user with memdup_user_nul Thorsten Blum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251114160416.230513-2-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=alexander.shishkin@linux.intel.com \
--cc=alexandre.torgue@foss.st.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).