[PATCH] cgroup/rdma: fix strncmp prefix match in parse_resource()

cuitao
2026-04-14T02:09:56Z

parse_resource() used strncmp(value, "max", strlen(value)) to match the
"max" keyword. Since strlen(value) is the comparison length, prefixes
like "ma" or "m" are incorrectly accepted as "max".

Fix by replacing strncmp with strcmp for exact matching and remove the
now unused `len` variable.

Signed-off-by: cuitao <cuitao@kylinos.cn>
---
kernel/cgroup/rdma.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/cgroup/rdma.c b/kernel/cgroup/rdma.c
index 09258eebb5c7..81e278348dad 100644
--- a/kernel/cgroup/rdma.c
+++ b/kernel/cgroup/rdma.c
@@ -359,7 +359,6 @@ static int parse_resource(char *c, int *intval)
{
substring_t argstr;
char *name, *value = c;
- size_t len;
int ret, i;

name = strsep(&value, "=");
@@ -370,10 +369,8 @@ static int parse_resource(char *c, int *intval)
if (i < 0)
return i;

- len = strlen(value);
-
argstr.from = value;
- argstr.to = value + len;
+ argstr.to = value + strlen(value);

ret = match_int(&argstr, intval);
if (ret >= 0) {
@@ -381,7 +378,7 @@ static int parse_resource(char *c, int *intval)
return -EINVAL;
return i;
}
- if (strncmp(value, RDMACG_MAX_STR, len) == 0) {
+ if (strcmp(value, RDMACG_MAX_STR) == 0) {
*intval = S32_MAX;
return i;
}
--
2.43.0