From: Thorsten Blum <thorsten.blum@linux.dev>
To: Rich Felker <dalias@libc.org>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Tim Bird <tim.bird@sony.com>, Danilo Krummrich <dakr@kernel.org>
Cc: linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org,
Thorsten Blum <thorsten.blum@linux.dev>
Subject: [PATCH] sh: platform_early: use strscpy in sh_early_platform_driver_register
Date: Tue, 5 May 2026 10:58:15 +0200 [thread overview]
Message-ID: <20260505085813.156242-3-thorsten.blum@linux.dev> (raw)
Use strscpy() to copy the early parameter to the destination buffer
instead of using memcpy() followed by a manual NUL termination. This
also makes the explicit ->bufsize guard unnecessary, remove it.
Return early when the parameter is NULL to avoid unnecessarily calling
strlen() on the driver name.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/sh/drivers/platform_early.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/arch/sh/drivers/platform_early.c b/arch/sh/drivers/platform_early.c
index ca73442a03a6..9600787ee181 100644
--- a/arch/sh/drivers/platform_early.c
+++ b/arch/sh/drivers/platform_early.c
@@ -3,6 +3,7 @@
#include <asm/platform_early.h>
#include <linux/mod_devicetable.h>
#include <linux/pm.h>
+#include <linux/string.h>
static __initdata LIST_HEAD(sh_early_platform_driver_list);
static __initdata LIST_HEAD(sh_early_platform_device_list);
@@ -74,12 +75,15 @@ int __init sh_early_platform_driver_register(struct sh_early_platform_driver *ep
list_add_tail(&epdrv->list, &sh_early_platform_driver_list);
}
+ if (!buf)
+ return 0;
+
/* If the user has specified device then make sure the driver
* gets prioritized. The driver of the last device specified on
* command line will be put first on the list.
*/
n = strlen(epdrv->pdrv->driver.name);
- if (buf && !strncmp(buf, epdrv->pdrv->driver.name, n)) {
+ if (!strncmp(buf, epdrv->pdrv->driver.name, n)) {
list_move(&epdrv->list, &sh_early_platform_driver_list);
/* Allow passing parameters after device name */
@@ -99,11 +103,7 @@ int __init sh_early_platform_driver_register(struct sh_early_platform_driver *ep
if (buf[n] == ',')
n++;
- if (epdrv->bufsize) {
- memcpy(epdrv->buffer, &buf[n],
- min_t(int, epdrv->bufsize, strlen(&buf[n]) + 1));
- epdrv->buffer[epdrv->bufsize - 1] = '\0';
- }
+ strscpy(epdrv->buffer, &buf[n], epdrv->bufsize);
}
return 0;
reply other threads:[~2026-05-05 8:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260505085813.156242-3-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=dakr@kernel.org \
--cc=dalias@libc.org \
--cc=geert+renesas@glider.be \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=tim.bird@sony.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