From: Niklas Schnelle <schnelle@linux.ibm.com>
To: Thorsten Blum <thorsten.blum@linux.dev>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Halil Pasic <pasic@linux.ibm.com>,
"Bill O'Donnell" <bodonnel@redhat.com>,
Al Viro <viro@zeniv.linux.org.uk>,
Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>,
Joel Granados <joel.granados@kernel.org>
Cc: Wei Liu <wei.liu@kernel.org>,
linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] s390/debug: Replace kmalloc() + copy_from_user() with memdup_user_nul()
Date: Thu, 04 Sep 2025 14:14:16 +0200 [thread overview]
Message-ID: <5d2282ef995adddec86ae8e3240cd3f59f50b3e4.camel@linux.ibm.com> (raw)
In-Reply-To: <20250904114031.353365-2-thorsten.blum@linux.dev>
On Thu, 2025-09-04 at 13:40 +0200, Thorsten Blum wrote:
> Replace kmalloc() followed by copy_from_user() with memdup_user_nul() to
> improve and simplify debug_get_user_string(). Remove the manual
> NUL-termination.
>
> No functional changes intended.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> arch/s390/kernel/debug.c | 12 +++---------
> 1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/arch/s390/kernel/debug.c b/arch/s390/kernel/debug.c
> index c62100dc62c8..6a26f202441d 100644
> --- a/arch/s390/kernel/debug.c
> +++ b/arch/s390/kernel/debug.c
> @@ -1416,18 +1416,12 @@ static inline char *debug_get_user_string(const char __user *user_buf,
> {
> char *buffer;
>
> - buffer = kmalloc(user_len + 1, GFP_KERNEL);
> - if (!buffer)
> - return ERR_PTR(-ENOMEM);
> - if (copy_from_user(buffer, user_buf, user_len) != 0) {
> - kfree(buffer);
> - return ERR_PTR(-EFAULT);
> - }
> + buffer = memdup_user_nul(user_buf, user_len);
> + if (IS_ERR(buffer))
> + return buffer;
> /* got the string, now strip linefeed. */
> if (buffer[user_len - 1] == '\n')
> buffer[user_len - 1] = 0;
> - else
> - buffer[user_len] = 0;
> return buffer;
> }
>
I like it, thanks!
Reviewed-by: Niklas Schnelle <schnelle@linux.ibm.com>
next prev parent reply other threads:[~2025-09-04 12:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-04 11:40 [PATCH] s390/debug: Replace kmalloc() + copy_from_user() with memdup_user_nul() Thorsten Blum
2025-09-04 12:14 ` Niklas Schnelle [this message]
2025-09-08 11:50 ` Alexander Gordeev
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=5d2282ef995adddec86ae8e3240cd3f59f50b3e4.camel@linux.ibm.com \
--to=schnelle@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=bodonnel@redhat.com \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=joel.granados@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=pasic@linux.ibm.com \
--cc=svens@linux.ibm.com \
--cc=thorsten.blum@linux.dev \
--cc=tigran.mkrtchyan@desy.de \
--cc=viro@zeniv.linux.org.uk \
--cc=wei.liu@kernel.org \
/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