From: Thorsten Blum <thorsten.blum@linux.dev>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next] net: rfkill: Replace strcpy with memcpy to improve rfkill_alloc
Date: Mon, 15 Dec 2025 13:20:36 +0100 [thread overview]
Message-ID: <20251215122036.379322-2-thorsten.blum@linux.dev> (raw)
strcpy() is deprecated [1] and uses an additional strlen() internally;
use memcpy() directly since we already know the length of 'name' and
that it is guaranteed to be NUL-terminated.
Use struct_size(), which provides additional compile-time checks for
structures with flexible array members (e.g., __must_be_array()), to
determine the allocation size for a new 'struct rfkill'.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
net/rfkill/core.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index 7d3e82e4c2fc..db1260acb182 100644
--- a/net/rfkill/core.c
+++ b/net/rfkill/core.c
@@ -986,6 +986,7 @@ struct rfkill * __must_check rfkill_alloc(const char *name,
{
struct rfkill *rfkill;
struct device *dev;
+ size_t name_sz;
if (WARN_ON(!ops))
return NULL;
@@ -999,14 +1000,15 @@ struct rfkill * __must_check rfkill_alloc(const char *name,
if (WARN_ON(type == RFKILL_TYPE_ALL || type >= NUM_RFKILL_TYPES))
return NULL;
- rfkill = kzalloc(sizeof(*rfkill) + strlen(name) + 1, GFP_KERNEL);
+ name_sz = strlen(name) + 1;
+ rfkill = kzalloc(struct_size(rfkill, name, name_sz), GFP_KERNEL);
if (!rfkill)
return NULL;
spin_lock_init(&rfkill->lock);
INIT_LIST_HEAD(&rfkill->node);
rfkill->type = type;
- strcpy(rfkill->name, name);
+ memcpy(rfkill->name, name, name_sz);
rfkill->ops = ops;
rfkill->data = ops_data;
--
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
next reply other threads:[~2025-12-15 12:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-15 12:20 Thorsten Blum [this message]
2026-01-08 12:29 ` [PATCH net-next] net: rfkill: Replace strcpy with memcpy to improve rfkill_alloc Johannes Berg
2026-02-20 17:00 ` 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=20251215122036.379322-2-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=johannes@sipsolutions.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.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