* [PATCH] sh: machvec: clean up and use strscpy() in early_parse_mv
@ 2026-04-23 11:15 Thorsten Blum
0 siblings, 0 replies; only message in thread
From: Thorsten Blum @ 2026-04-23 11:15 UTC (permalink / raw)
To: Rich Felker, John Paul Adrian Glaubitz
Cc: Thorsten Blum, linux-sh, linux-kernel
Use strscpy() to copy the NUL-terminated early parameter 'from' to the
destination buffer instead of using memcpy() followed by a manual NUL
termination. If the early parameter contains a space, use min() to copy
only up to that delimiter, otherwise copy the entire string. Drop the
now unused 'mv_len' variable.
Remove the redundant 'mv_name' initialization because it is immediately
populated by strscpy(). Drop 'mv_comma', which has been unused since
commit 9655ad03af2d ("sh: Fixup machvec support."), and remove the dead
'from = mv_end' assignment. Since panic() is a '__noreturn' function,
remove the else branch as well.
Change 'machvec_selected' from unsigned int to bool and move
'__initdata' after the variable name to silence a checkpatch warning.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/sh/kernel/machvec.c | 27 ++++++++++-----------------
1 file changed, 10 insertions(+), 17 deletions(-)
diff --git a/arch/sh/kernel/machvec.c b/arch/sh/kernel/machvec.c
index 57efaf5b82ae..d737a5a560cd 100644
--- a/arch/sh/kernel/machvec.c
+++ b/arch/sh/kernel/machvec.c
@@ -8,6 +8,7 @@
* Copyright (C) 2002 - 2007 Paul Mundt
*/
#include <linux/init.h>
+#include <linux/minmax.h>
#include <linux/string.h>
#include <asm/machvec.h>
#include <asm/sections.h>
@@ -35,29 +36,21 @@ static struct sh_machine_vector * __init get_mv_byname(const char *name)
return NULL;
}
-static unsigned int __initdata machvec_selected;
+static bool machvec_selected __initdata;
static int __init early_parse_mv(char *from)
{
- char mv_name[MV_NAME_SIZE] = "";
+ char mv_name[MV_NAME_SIZE];
char *mv_end;
- char *mv_comma;
- int mv_len;
struct sh_machine_vector *mvp;
mv_end = strchr(from, ' ');
- if (mv_end == NULL)
- mv_end = from + strlen(from);
+ if (mv_end)
+ strscpy(mv_name, from, min(mv_end - from + 1, MV_NAME_SIZE));
+ else
+ strscpy(mv_name, from);
- mv_comma = strchr(from, ',');
- mv_len = mv_end - from;
- if (mv_len > (MV_NAME_SIZE-1))
- mv_len = MV_NAME_SIZE-1;
- memcpy(mv_name, from, mv_len);
- mv_name[mv_len] = '\0';
- from = mv_end;
-
- machvec_selected = 1;
+ machvec_selected = true;
/* Boot with the generic vector */
if (strcmp(mv_name, "generic") == 0)
@@ -71,8 +64,8 @@ static int __init early_parse_mv(char *from)
pr_cont("\n\n");
panic("Failed to select machvec '%s' -- halting.\n",
mv_name);
- } else
- sh_mv = *mvp;
+ }
+ sh_mv = *mvp;
return 0;
}
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-04-23 11:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-23 11:15 [PATCH] sh: machvec: clean up and use strscpy() in early_parse_mv Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox