From: Thorsten Blum <thorsten.blum@linux.dev>
To: Rich Felker <dalias@libc.org>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] sh: machvec: clean up and use strscpy() in early_parse_mv
Date: Thu, 23 Apr 2026 13:15:16 +0200 [thread overview]
Message-ID: <20260423111516.211532-3-thorsten.blum@linux.dev> (raw)
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;
}
reply other threads:[~2026-04-23 11:16 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=20260423111516.211532-3-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=dalias@libc.org \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sh@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