Skip to content

Commit cc659e7

Browse files
andy-shevhtejun
authored andcommitted
rdmacg: Convert to use match_string() helper
The new helper returns index of the matching string in an array. We are going to use it here. Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent c43c5ea commit cc659e7

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

kernel/cgroup/rdma.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -362,35 +362,32 @@ EXPORT_SYMBOL(rdmacg_unregister_device);
362362
static int parse_resource(char *c, int *intval)
363363
{
364364
substring_t argstr;
365-
const char **table = &rdmacg_resource_names[0];
366365
char *name, *value = c;
367366
size_t len;
368-
int ret, i = 0;
367+
int ret, i;
369368

370369
name = strsep(&value, "=");
371370
if (!name || !value)
372371
return -EINVAL;
373372

374-
len = strlen(value);
373+
i = match_string(rdmacg_resource_names, RDMACG_RESOURCE_MAX, name);
374+
if (i < 0)
375+
return i;
375376

376-
for (i = 0; i < RDMACG_RESOURCE_MAX; i++) {
377-
if (strcmp(table[i], name))
378-
continue;
377+
len = strlen(value);
379378

380-
argstr.from = value;
381-
argstr.to = value + len;
379+
argstr.from = value;
380+
argstr.to = value + len;
382381

383-
ret = match_int(&argstr, intval);
384-
if (ret >= 0) {
385-
if (*intval < 0)
386-
break;
387-
return i;
388-
}
389-
if (strncmp(value, RDMACG_MAX_STR, len) == 0) {
390-
*intval = S32_MAX;
391-
return i;
392-
}
393-
break;
382+
ret = match_int(&argstr, intval);
383+
if (ret >= 0) {
384+
if (*intval < 0)
385+
return -EINVAL;
386+
return i;
387+
}
388+
if (strncmp(value, RDMACG_MAX_STR, len) == 0) {
389+
*intval = S32_MAX;
390+
return i;
394391
}
395392
return -EINVAL;
396393
}

0 commit comments

Comments
 (0)