summaryrefslogtreecommitdiff
path: root/drivers/nvme
diff options
context:
space:
mode:
authorliyouhong <liyouhong@kylinos.cn>2026-05-29 16:51:43 +0800
committerKeith Busch <kbusch@kernel.org>2026-06-02 03:16:26 -0700
commit4cf06977bdb6a037e2717b4117f3fd636f6e9641 (patch)
tree9eafe7c965dc0a603f551e4002b0a33d384c387f /drivers/nvme
parentf078d1aa52a4481cbf4d12c1543639d65a020d3b (diff)
downloadlinux-next-4cf06977bdb6a037e2717b4117f3fd636f6e9641.tar.gz
linux-next-4cf06977bdb6a037e2717b4117f3fd636f6e9641.zip
nvme-multipath: require exact iopolicy names for module parameter
The iopolicy module parameter uses strncmp prefix matching, so values like "numax" are accepted as "numa". The per-subsystem sysfs attribute already requires an exact match via sysfs_streq(). Parse both through a shared helper so invalid values are rejected consistently. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: liyouhong <liyouhong@kylinos.cn> Signed-off-by: Keith Busch <kbusch@kernel.org>
Diffstat (limited to 'drivers/nvme')
-rw-r--r--drivers/nvme/host/multipath.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index e00e2842df30..d6c51f59ff25 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -73,19 +73,29 @@ static const char *nvme_iopolicy_names[] = {
static int iopolicy = NVME_IOPOLICY_NUMA;
+static int nvme_iopolicy_parse(const char *str)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(nvme_iopolicy_names); i++) {
+ if (sysfs_streq(str, nvme_iopolicy_names[i]))
+ return i;
+ }
+ return -EINVAL;
+}
+
static int nvme_set_iopolicy(const char *val, const struct kernel_param *kp)
{
+ int policy;
+
if (!val)
return -EINVAL;
- if (!strncmp(val, "numa", 4))
- iopolicy = NVME_IOPOLICY_NUMA;
- else if (!strncmp(val, "round-robin", 11))
- iopolicy = NVME_IOPOLICY_RR;
- else if (!strncmp(val, "queue-depth", 11))
- iopolicy = NVME_IOPOLICY_QD;
- else
- return -EINVAL;
+ policy = nvme_iopolicy_parse(val);
+ if (policy < 0)
+ return policy;
+
+ iopolicy = policy;
return 0;
}
@@ -1039,16 +1049,14 @@ static ssize_t nvme_subsys_iopolicy_store(struct device *dev,
{
struct nvme_subsystem *subsys =
container_of(dev, struct nvme_subsystem, dev);
- int i;
+ int policy;
- for (i = 0; i < ARRAY_SIZE(nvme_iopolicy_names); i++) {
- if (sysfs_streq(buf, nvme_iopolicy_names[i])) {
- nvme_subsys_iopolicy_update(subsys, i);
- return count;
- }
- }
+ policy = nvme_iopolicy_parse(buf);
+ if (policy < 0)
+ return policy;
- return -EINVAL;
+ nvme_subsys_iopolicy_update(subsys, policy);
+ return count;
}
SUBSYS_ATTR_RW(iopolicy, S_IRUGO | S_IWUSR,
nvme_subsys_iopolicy_show, nvme_subsys_iopolicy_store);