From: Thorsten Blum <thorsten.blum@linux.dev>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] platform: Replace deprecated strcpy in platform_device_alloc
Date: Fri, 31 Oct 2025 13:50:28 +0100 [thread overview]
Message-ID: <4AB5FFA3-EFF9-41FA-8204-FA66FA9D33FF@linux.dev> (raw)
In-Reply-To: <2025103140-plant-sprig-bdda@gregkh>
On 31. Oct 2025, at 13:24, Greg Kroah-Hartman wrote:
> On Fri, Oct 31, 2025 at 01:18:58PM +0100, Thorsten Blum wrote:
>> First, use struct_size(), which provides additional compile-time checks
>> for structures with flexible array members (e.g., __must_be_array()), to
>> calculate the number of bytes to allocate for a new 'platform_object'.
>>
>> Then, since we know the length of 'name' and that it is guaranteed to be
>> NUL-terminated, replace the deprecated strcpy() with a simple memcpy().
>
> This makes no sense. You are saying we know the length, and we know it
> is NULL terminated, so let's be complex and do a strlen() and memcpy()
> instead of a normal strcpy().
The current version already calculates strlen(name), and then strcpy()
does another strlen() internally, which we can safely skip by using
memcpy() directly.
The current code is correct, but by removing the deprecated strcpy(), we
also remove a redundant call to strlen() without any functional changes.
prev parent reply other threads:[~2025-10-31 12:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-31 12:18 Thorsten Blum
2025-10-31 12:24 ` Greg Kroah-Hartman
2025-10-31 12:50 ` Thorsten Blum [this message]
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=4AB5FFA3-EFF9-41FA-8204-FA66FA9D33FF@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=dakr@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@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
all inboxes | Powered by JetHome®