public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cgroup/rdma: fix strncmp prefix match in parse_resource()
@ 2026-04-14  2:09 cuitao
  2026-04-15 13:37 ` Michal Koutný
  0 siblings, 1 reply; 8+ messages in thread
From: cuitao @ 2026-04-14  2:09 UTC (permalink / raw)
  To: tj, hannes, mkoutny, cgroups; +Cc: cuitao

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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-04-22  2:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-14  2:09 [PATCH] cgroup/rdma: fix strncmp prefix match in parse_resource() cuitao
2026-04-15 13:37 ` Michal Koutný
2026-04-17  6:43   ` 崔涛
2026-04-17  9:53     ` Michal Koutný
2026-04-20  1:08       ` Tao Cui
2026-04-20  4:52       ` [PATCH v2] cgroup/rdma: refactor resource parsing with match_table_t/match_token() cuitao
2026-04-21 16:42         ` Tejun Heo
2026-04-22  2:17           ` [PATCH v3] " Tao Cui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox