* [PATCH] sh: platform_early: use strscpy in sh_early_platform_driver_register
@ 2026-05-05 8:58 Thorsten Blum
0 siblings, 0 replies; only message in thread
From: Thorsten Blum @ 2026-05-05 8:58 UTC (permalink / raw)
To: Rich Felker, John Paul Adrian Glaubitz, Geert Uytterhoeven,
Tim Bird, Danilo Krummrich
Cc: linux-sh, linux-kernel, Thorsten Blum
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;
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-05-05 8:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-05 8:58 [PATCH] sh: platform_early: use strscpy in sh_early_platform_driver_register Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox