From: Hans de Goede <hdegoede@redhat.com>
To: Steve Wahl <steve.wahl@hpe.com>,
Justin Ernst <justin.ernst@hpe.com>,
Kyle Meyer <kyle.meyer@hpe.com>,
Dimitri Sivanich <dimitri.sivanich@hpe.com>,
Russ Anderson <russ.anderson@hpe.com>,
Darren Hart <dvhart@infradead.org>,
Andy Shevchenko <andy@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H . Peter Anvin" <hpa@zytor.com>
Cc: Hans de Goede <hdegoede@redhat.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
Justin Stitt <justinstitt@google.com>
Subject: [PATCH] x86/platform/uv: Use sysfs_match_string() for string parsing in param_set_action()
Date: Wed, 13 Sep 2023 17:16:56 +0200 [thread overview]
Message-ID: <20230913151656.52792-1-hdegoede@redhat.com> (raw)
Remove the custom, hard to read code to:
1. Make a copy of "val" with any potential '\n' at the end stripped
2. Compare the copy against an array of allowed string values
Linux has the sysfs_match_string() helper exactly for cases like this,
switch to this.
Cc: Justin Stitt <justinstitt@google.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
arch/x86/platform/uv/uv_nmi.c | 48 +++++++++++++++++++----------------
1 file changed, 26 insertions(+), 22 deletions(-)
diff --git a/arch/x86/platform/uv/uv_nmi.c b/arch/x86/platform/uv/uv_nmi.c
index 45d0c17ce77c..44bacb547c65 100644
--- a/arch/x86/platform/uv/uv_nmi.c
+++ b/arch/x86/platform/uv/uv_nmi.c
@@ -179,17 +179,27 @@ module_param_named(debug, uv_nmi_debug, int, 0644);
/* Valid NMI Actions */
#define ACTION_LEN 16
-static struct nmi_action {
- char *action;
- char *desc;
-} valid_acts[] = {
- { "kdump", "do kernel crash dump" },
- { "dump", "dump process stack for each cpu" },
- { "ips", "dump Inst Ptr info for each cpu" },
- { "kdb", "enter KDB (needs kgdboc= assignment)" },
- { "kgdb", "enter KGDB (needs gdb target remote)" },
- { "health", "check if CPUs respond to NMI" },
+
+static const char * const valid_acts[] = {
+ "kdump",
+ "dump",
+ "ips",
+ "kdb",
+ "kgdb",
+ "health",
};
+
+static const char * const valid_acts_desc[] = {
+ "do kernel crash dump",
+ "dump process stack for each cpu",
+ "dump Inst Ptr info for each cpu",
+ "enter KDB (needs kgdboc= assignment)",
+ "enter KGDB (needs gdb target remote)",
+ "check if CPUs respond to NMI",
+};
+
+static_assert(ARRAY_SIZE(valid_acts) == ARRAY_SIZE(valid_acts_desc));
+
typedef char action_t[ACTION_LEN];
static action_t uv_nmi_action = { "dump" };
@@ -202,25 +212,19 @@ static int param_set_action(const char *val, const struct kernel_param *kp)
{
int i;
int n = ARRAY_SIZE(valid_acts);
- char arg[ACTION_LEN];
- /* (remove possible '\n') */
- strscpy(arg, val, strnchrnul(val, sizeof(arg)-1, '\n') - val + 1);
+ i = sysfs_match_string(valid_acts, val);
- for (i = 0; i < n; i++)
- if (!strcmp(arg, valid_acts[i].action))
- break;
-
- if (i < n) {
- strscpy(uv_nmi_action, arg, sizeof(uv_nmi_action));
+ if (i >= 0) {
+ strscpy(uv_nmi_action, valid_acts[i], sizeof(uv_nmi_action));
pr_info("UV: New NMI action:%s\n", uv_nmi_action);
return 0;
}
- pr_err("UV: Invalid NMI action:%s, valid actions are:\n", arg);
+ pr_err("UV: Invalid NMI action:%s, valid actions are:\n", val);
for (i = 0; i < n; i++)
- pr_err("UV: %-8s - %s\n",
- valid_acts[i].action, valid_acts[i].desc);
+ pr_err("UV: %-8s - %s\n", valid_acts[i], valid_acts_desc[i]);
+
return -EINVAL;
}
--
2.41.0
next reply other threads:[~2023-09-13 15:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-13 15:16 Hans de Goede [this message]
2023-09-13 16:56 ` Steve Wahl
2023-09-13 17:01 ` Hans de Goede
2023-09-13 17:03 ` Steve Wahl
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=20230913151656.52792-1-hdegoede@redhat.com \
--to=hdegoede@redhat.com \
--cc=andy@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dimitri.sivanich@hpe.com \
--cc=dvhart@infradead.org \
--cc=hpa@zytor.com \
--cc=justin.ernst@hpe.com \
--cc=justinstitt@google.com \
--cc=kyle.meyer@hpe.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=russ.anderson@hpe.com \
--cc=steve.wahl@hpe.com \
--cc=tglx@linutronix.de \
--cc=x86@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
all inboxes | Powered by JetHome®